CameraComponentSystem.cs 993 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. if (self.Unit != null)
  30. {
  31. self.UpdatePosition();
  32. }
  33. }
  34. private static void UpdatePosition(this CameraComponent self)
  35. {
  36. Vector3 cameraPos = self.mainCamera.transform.position;
  37. self.mainCamera.transform.position = new Vector3(self.Unit.Position.x, cameraPos.y, self.Unit.Position.z - 10);
  38. }
  39. }
  40. }