| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using UnityEngine;
- namespace Model
- {
- [ObjectEvent]
- public class CameraComponentEvent : ObjectEvent<CameraComponent>, IAwake, ILateUpdate
- {
- public void Awake()
- {
- this.Get().Awake();
- }
- public void LateUpdate()
- {
- this.Get().LateUpdate();
- }
- }
- public class CameraComponent : Component
- {
- // 战斗摄像机
- public Camera mainCamera;
- public Unit Unit;
- public Camera MainCamera
- {
- get
- {
- return this.mainCamera;
- }
- }
- public void Awake()
- {
- this.mainCamera = Camera.main;
- }
- public void LateUpdate()
- {
- // 摄像机每帧更新位置
- UpdatePosition();
- }
- private void UpdatePosition()
- {
- Vector3 cameraPos = this.mainCamera.transform.position;
- this.mainCamera.transform.position = new Vector3(this.Unit.Position.x, cameraPos.y, this.Unit.Position.z - 1);
- }
- }
- }
|