12345678910 |
- {
- "code": "var Vector3 = Laya.Vector3;\r\nimport { GameUtils } from \"../../GameUtils/GameUtils\";\r\nexport default class CameraManager extends Laya.Script {\r\n constructor() {\r\n super();\r\n this.follow = false;\r\n this.lookat = false;\r\n this.offest = new Vector3();\r\n this.curCameraPos = new Vector3();\r\n this.startPos = new Vector3();\r\n this.starRot = new Vector3();\r\n this.forwardDistance = 2;\r\n this.addspeed = 1;\r\n this.followrate = 0.3;\r\n this.lerpPos = new Vector3();\r\n this.lerprot = new Laya.Quaternion();\r\n this.lookdir = new Vector3();\r\n this.offesty = 0;\r\n this.offestz = 0;\r\n CameraManager.CameraManagerInstance = this;\r\n }\r\n static get Instance() {\r\n return CameraManager.CameraManagerInstance;\r\n }\r\n onAwake() {\r\n this.camera = this.owner;\r\n }\r\n SetFollow(_target, _lookat = false) {\r\n this.curTarget = _target;\r\n Vector3.subtract(_target.position, this.camera.transform.position, this.offest);\r\n this.follow = true;\r\n this.lookat = _lookat;\r\n this.startPos = this.camera.transform.position.clone();\r\n this.starRot = this.camera.transform.rotationEuler.clone();\r\n Laya.timer.clearAll(this);\r\n }\r\n StopFollow() {\r\n this.follow = false;\r\n this.curTarget = null;\r\n this.offesty = 0;\r\n this.offestz = 0;\r\n this.offest = new Vector3(0, 0, 0);\r\n this.curCameraPos = new Vector3(0, 0, 0);\r\n this.lerpPos = new Vector3(0, 0, 0);\r\n }\r\n PauseFollow() {\r\n this.follow = false;\r\n }\r\n ResumeFollow() {\r\n this.follow = true;\r\n }\r\n onUpdate() {\r\n if (this.follow && this.curTarget) {\r\n Vector3.subtract(this.curTarget.position, this.offest, this.curCameraPos);\r\n this.offesty = GameUtils.lerp(this.offesty, 1, 0.02);\r\n this.curCameraPos = new Vector3(this.curCameraPos.x, this.curCameraPos.y + this.offesty, this.curCameraPos.z + this.offestz);\r\n Vector3.lerp(this.camera.transform.position, this.curCameraPos, this.followrate, this.lerpPos);\r\n this.camera.transform.position = new Vector3(this.curCameraPos.x, this.lerpPos.y, this.lerpPos.z);\r\n var quaternion1 = new Laya.Quaternion();\r\n var lookpos = new Vector3(this.lerpPos.x, this.lerpPos.y - 0.7, this.lerpPos.z);\r\n Laya.Quaternion.lookAt(lookpos, this.curTarget.position, new Vector3(0, 1, 0), quaternion1);\r\n quaternion1.invert(quaternion1);\r\n Laya.Quaternion.slerp(this.camera.transform.rotation, quaternion1, 0.05, quaternion1);\r\n this.camera.transform.rotation = quaternion1;\r\n }\r\n }\r\n SetCameraPos() {\r\n Vector3.subtract(this.curTarget.position, this.offest, this.curCameraPos);\r\n Vector3.lerp(this.camera.transform.position, this.curCameraPos, 0.7, this.lerpPos);\r\n this.camera.transform.position = new Vector3(this.lerpPos.x, this.camera.transform.position.y, this.camera.transform.position.z);\r\n }\r\n get GetCurCameraPos() {\r\n Vector3.subtract(this.curTarget.position, this.offest, this.curCameraPos);\r\n return this.curCameraPos;\r\n }\r\n}\r\n",
- "references": [
- "C:/Users/admin/Desktop/runner/src/Scripts/Game/EventManager.ts",
- "C:/Users/admin/Desktop/runner/src/Scripts/Game/GameManager.ts",
- "C:/Users/admin/Desktop/runner/src/Scripts/Game/LevelManager.ts",
- "C:/Users/admin/Desktop/runner/src/GameUtils/GameUtils.ts"
- ]
- }
|