CameraAnimTransformProxy.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using UnityEngine;
  3. namespace SceneStory
  4. {
  5. public class CameraAnimTransformProxy : BaseBehaviour
  6. {
  7. private void OnEnable()
  8. {
  9. this.cam = Camera.main.transform.parent;
  10. }
  11. private void OnDisable()
  12. {
  13. if (!SingletonMono<CameraController>.ApplicationIsQuitting)
  14. {
  15. SingletonMono<CameraController>.Instance.IsFollowPivot = true;
  16. }
  17. }
  18. private void Update()
  19. {
  20. if (this.cam == null)
  21. {
  22. return;
  23. }
  24. if (SingletonMono<CameraController>.Instance != null)
  25. {
  26. SingletonMono<CameraController>.Instance.IsFollowPivot = (!this.refreshOffset && !this.refreshPos);
  27. }
  28. if (this.refreshPos)
  29. {
  30. this.cam.position = base.transform.position;
  31. }
  32. if (this.refreshOffset)
  33. {
  34. Vector3 position = this.cam.position + (this.offset - this.lastOffset);
  35. this.lastOffset = this.offset;
  36. this.cam.position = position;
  37. }
  38. }
  39. private Transform cam;
  40. private Vector3 lastOffset = Vector3.zero;
  41. [Header("开启该属性即可通过直接编辑Transform来同步位置")]
  42. public bool refreshPos;
  43. public Vector3 offset = Vector3.zero;
  44. [Header("开启该属性即可通过直接offset来同步相对位置")]
  45. public bool refreshOffset;
  46. }
  47. }