CameraComponent.cs 936 B

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