CameraComponent.cs 838 B

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