{ "code": "var Vector3 = Laya.Vector3;\r\nimport Game_Tool from \"../Util/Game_Tool\";\r\nimport PlayerController from \"./PlayerController\";\r\nimport { Mathf } from \"../Util/Mathf\";\r\nimport { EventManager, EventType } from \"./EventManager\";\r\nexport var CameraState;\r\n(function (CameraState) {\r\n CameraState[CameraState[\"game\"] = 1] = \"game\";\r\n CameraState[CameraState[\"top\"] = 2] = \"top\";\r\n CameraState[CameraState[\"fail\"] = 3] = \"fail\";\r\n CameraState[CameraState[\"win\"] = 4] = \"win\";\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.ismoving = false;\r\n this.isIngameMove = 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 A() {\r\n }\r\n onAwake() {\r\n this.selfObj = this.owner;\r\n this._tran = this.selfObj.transform;\r\n console.log(\"camera pos:\" + JSON.stringify(this._tran.position));\r\n let origSize = this.selfObj.fieldOfView;\r\n this.nowP = Mathf.VecZero;\r\n this.nowR = Mathf.VecZero;\r\n EventManager.on(EventType.Event.CamFollowArg, this, this.SetMoveArg);\r\n }\r\n SetCameraByState(type, arg, isgamemove = false) {\r\n if (arg)\r\n this.arg = arg;\r\n switch (type) {\r\n case CameraState.game:\r\n this.tarTra = PlayerController.Instance.ViewPoint;\r\n if (isgamemove) {\r\n this.StopMove();\r\n this.isIngameMove = true;\r\n }\r\n else {\r\n Laya.timer.clear(this, this.StopMove);\r\n Laya.timer.frameLoop(1, this, this.CameraMove);\r\n this.ismoving = true;\r\n }\r\n break;\r\n case CameraState.top:\r\n this.tarTra = PlayerController.Instance.TopViewPoint;\r\n if (!this.ismoving) {\r\n this.isIngameMove = false;\r\n Laya.timer.frameLoop(1, this, this.CameraMove);\r\n }\r\n break;\r\n case CameraState.fail:\r\n this.tarTra = PlayerController.Instance.FailViewPoint;\r\n if (!this.ismoving) {\r\n this.isIngameMove = false;\r\n Laya.timer.frameLoop(1, this, this.CameraMove);\r\n }\r\n Laya.timer.once(2000, this, this.StopMove);\r\n break;\r\n case CameraState.win:\r\n this.tarTra = PlayerController.Instance.WinViewPoint;\r\n if (!this.ismoving) {\r\n this.isIngameMove = false;\r\n Laya.timer.frameLoop(1, this, this.CameraMove);\r\n }\r\n Laya.timer.once(2000, this, this.StopMove);\r\n break;\r\n }\r\n }\r\n StopMove() {\r\n this.ismoving = false;\r\n this.isIngameMove = false;\r\n Laya.timer.clear(this, this.CameraMove);\r\n }\r\n MoveS() {\r\n if (!this.isIngameMove)\r\n return;\r\n this._tran.position = this.tarTra.position.clone();\r\n this._tran.localRotationEuler = Mathf.SpToCam(this.tarTra.localRotationEuler.clone());\r\n }\r\n CameraMove() {\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 SetMoveArg(arg) {\r\n this.arg = arg;\r\n }\r\n SetCameraSize(isAdd) {\r\n let tar;\r\n let t;\r\n if (isAdd) {\r\n t = 500;\r\n tar = this.nowSize + 25;\r\n }\r\n else {\r\n tar = this.nowSize;\r\n t = 1000;\r\n }\r\n this.sizeTween = Laya.Tween.to(this.selfObj, { fieldOfView: tar }, t, null, Laya.Handler.create(this, () => {\r\n console.log(\"sizeTween com\");\r\n this.sizeTween.clear();\r\n }, null, false), null, true, false);\r\n }\r\n onDisable() {\r\n }\r\n onDestroy() {\r\n Laya.timer.clearAll(this);\r\n EventManager.off(EventType.Event.CamFollowArg, this, this.SetMoveArg);\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/GameLogic/PlayerController.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/Util/Mathf.ts", "D:/GitProject/GunGang/gungang_laya/gungang/src/GameLogic/EventManager.ts" ] }