CameraComponentSystem.cs 989 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using UnityEngine;
  2. namespace ET.Client
  3. {
  4. [FriendOf(typeof(CameraComponent))]
  5. public static class CameraComponentSystem
  6. {
  7. [ObjectSystem]
  8. public class CameraComponentAwakeSystem : AwakeSystem<CameraComponent>
  9. {
  10. protected override void Awake(CameraComponent self)
  11. {
  12. self.Awake();
  13. }
  14. }
  15. [ObjectSystem]
  16. public class CameraComponentLateUpdateSystem : LateUpdateSystem<CameraComponent>
  17. {
  18. protected override void LateUpdate(CameraComponent self)
  19. {
  20. self.LateUpdate();
  21. }
  22. }
  23. private static void Awake(this CameraComponent self)
  24. {
  25. self.mainCamera = Camera.main;
  26. }
  27. private static void LateUpdate(this CameraComponent self)
  28. {
  29. // 摄像机每帧更新位置
  30. self.UpdatePosition();
  31. }
  32. private static void UpdatePosition(this CameraComponent self)
  33. {
  34. Vector3 cameraPos = self.mainCamera.transform.position;
  35. self.mainCamera.transform.position = new Vector3(self.Unit.Position.x, cameraPos.y, self.Unit.Position.z - 1);
  36. }
  37. }
  38. }