CameraComponent.cs 989 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using UnityEngine;
  2. namespace ET
  3. {
  4. [ObjectSystem]
  5. public class CameraComponentAwakeSystem : AwakeSystem<CameraComponent>
  6. {
  7. public override void Awake(CameraComponent self)
  8. {
  9. self.Awake();
  10. }
  11. }
  12. [ObjectSystem]
  13. public class CameraComponentLateUpdateSystem : LateUpdateSystem<CameraComponent>
  14. {
  15. public override void LateUpdate(CameraComponent self)
  16. {
  17. self.LateUpdate();
  18. }
  19. }
  20. public class CameraComponent : Entity, IAwake, ILateUpdate
  21. {
  22. // 战斗摄像机
  23. public Camera mainCamera;
  24. public Unit Unit;
  25. public Camera MainCamera
  26. {
  27. get
  28. {
  29. return this.mainCamera;
  30. }
  31. }
  32. public void Awake()
  33. {
  34. this.mainCamera = Camera.main;
  35. }
  36. public void LateUpdate()
  37. {
  38. // 摄像机每帧更新位置
  39. UpdatePosition();
  40. }
  41. private void UpdatePosition()
  42. {
  43. Vector3 cameraPos = this.mainCamera.transform.position;
  44. this.mainCamera.transform.position = new Vector3(this.Unit.Position.x, cameraPos.y, this.Unit.Position.z - 1);
  45. }
  46. }
  47. }