12345678910111213 |
- {
- "code": "var Vector3 = Laya.Vector3;\r\nimport Game_Tool from \"../Util/Game_Tool\";\r\nimport { Mathf } from \"../Util/Mathf\";\r\nimport PlayerController from \"../Controller/PlayerController\";\r\nimport AirPlaneController from \"../Controller/AirPlaneController\";\r\nimport CamController from \"../Controller/CamController\";\r\nexport var CameraState;\r\n(function (CameraState) {\r\n CameraState[CameraState[\"game\"] = 1] = \"game\";\r\n CameraState[CameraState[\"jump\"] = 2] = \"jump\";\r\n})(CameraState || (CameraState = {}));\r\nexport default class CameraBehavior extends Laya.Script3D {\r\n constructor() {\r\n super();\r\n this.arg = 0.1;\r\n this.canmovegame = false;\r\n this.startShake = false;\r\n this.seconds = 0;\r\n this.started = false;\r\n this.quake = 0.3;\r\n }\r\n onAwake() {\r\n this.selfObj = this.owner;\r\n this._tran = this.selfObj.transform;\r\n this.nowP = Mathf.VecZero;\r\n this.nowR = Mathf.VecZero;\r\n this.dis = Mathf.VecZero;\r\n this.temp = Mathf.VecZero;\r\n }\r\n Init() {\r\n this.dis.x = PlayerController.Instance.playerStartPos.x - this._tran.position.x;\r\n this.dis.y = PlayerController.Instance.playerStartPos.y - this._tran.position.y;\r\n this.dis.z = PlayerController.Instance.playerStartPos.z - this._tran.position.z;\r\n }\r\n SetCameraByState(type, arg) {\r\n this.arg = arg;\r\n switch (type) {\r\n case CameraState.game:\r\n this.tarTra = PlayerController.Instance.playerTra;\r\n if (!this.tarTra)\r\n return;\r\n let t = CamController.Instance.startPosTra;\r\n this._tran.position = t.position.clone();\r\n this._tran.localRotationEuler = Mathf.SpToCam(t.localRotationEuler.clone());\r\n this.canmovegame = true;\r\n case CameraState.jump:\r\n this.tarTra = AirPlaneController.Instance.jumpCamTra;\r\n if (!this.tarTra)\r\n return;\r\n this.canmovegame = false;\r\n Laya.timer.frameLoop(1, this, this.JumpCameraMove);\r\n Laya.timer.once(3000, this, this.StopMove);\r\n break;\r\n }\r\n }\r\n StopMove() {\r\n Laya.timer.clear(this, this.JumpCameraMove);\r\n }\r\n MoveGame() {\r\n if (!this.canmovegame)\r\n return;\r\n this.temp.x = this.tarTra.position.x - this.dis.x;\r\n this.temp.y = this.tarTra.position.y - this.dis.y;\r\n this.temp.z = this.tarTra.position.z - this.dis.z;\r\n this._tran.position = this.temp.clone();\r\n }\r\n JumpCameraMove() {\r\n let p, r;\r\n if (this.arg == 1) {\r\n p = this.tarTra.position;\r\n r = Mathf.SpToCam(this.tarTra.localRotationEuler.clone());\r\n }\r\n else {\r\n p = Mathf.MixVector3(this._tran.position.clone(), this.tarTra.position, this.arg, this.nowP);\r\n r = Mathf.MixVector3(this._tran.localRotationEuler, Mathf.SpToCam(this.tarTra.localRotationEuler.clone()), this.arg, this.nowR);\r\n }\r\n this._tran.position = p;\r\n this._tran.localRotationEuler = r;\r\n }\r\n onDisable() {\r\n }\r\n onDestroy() {\r\n Laya.timer.clearAll(this);\r\n }\r\n ShakeFor(a, b) {\r\n this.camPOS = this.selfObj.transform.position.clone();\r\n this.seconds = a;\r\n this.started = true;\r\n this.startShake = true;\r\n this.quake = b;\r\n }\r\n onLateUpdate() {\r\n if (this.startShake) {\r\n this.Quake();\r\n }\r\n if (this.started) {\r\n this.started = false;\r\n Laya.timer.once(this.seconds * 1000, this, () => {\r\n this.startShake = false;\r\n this.selfObj.transform.position = this.camPOS;\r\n });\r\n }\r\n }\r\n Quake() {\r\n var x = Game_Tool.random_1to1() * this.quake;\r\n var y = Game_Tool.random_1to1() * this.quake;\r\n var z = Game_Tool.random_1to1() * this.quake;\r\n var temp = new Vector3(this.camPOS.x + Math.random() * this.quake, this.camPOS.y + Math.random() * this.quake, this.camPOS.z + Math.random() * this.quake);\r\n this.selfObj.transform.position = temp;\r\n }\r\n}\r\n",
- "references": [
- "D:/GitProject/GunGang/gungang_laya/gungang/src/game_module/GameSetting.ts",
- "D:/GitProject/GunGang/gungang_laya/gungang/src/Util/Game_Tool.ts",
- "D:/GitProject/GunGang/gungang_laya/gungang/src/Util/Mathf.ts",
- "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/EventManager.ts",
- "D:/GitProject/GunGang/gungang_laya/gungang/src/Controller/PlayerController.ts",
- "D:/GitProject/GunGang/gungang_laya/gungang/src/Controller/AirPlaneController.ts",
- "D:/GitProject/GunGang/gungang_laya/gungang/src/Controller/CamController.ts"
- ]
- }
|