Zoom2D.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System;
  2. using UnityEngine;
  3. using System.Collections;
  4. public enum ZoomPhase
  5. {
  6. Stay,
  7. Forward,
  8. Bacward,
  9. }
  10. public class Zoom2D : MoveRoot
  11. {
  12. #region 变量
  13. public float Stay;
  14. public float Timer;
  15. public float Duration;
  16. public float TempTime;
  17. public float OnewayTime;
  18. public float SizeDelta;
  19. public float SizeOrigin;
  20. public float SizeDestination;
  21. public Vector3 PosDelta;
  22. public Vector3 PosOrigin;
  23. public Vector3 PosDestination;
  24. public Camera Camera;
  25. public Transform Target;
  26. public ZoomPhase Phase;
  27. public CurveFunctionF SizeFunc;
  28. public CurveFunctionV VecFunc;
  29. #endregion
  30. public Zoom2D(Camera camera)
  31. {
  32. Camera = camera;
  33. }
  34. public override bool DoForward()
  35. {
  36. Timer += Time.fixedDeltaTime;
  37. if (Timer < TempTime)
  38. {
  39. if (Phase == ZoomPhase.Forward)
  40. {
  41. Camera.orthographicSize = SizeFunc(Timer, OnewayTime, SizeOrigin, SizeDelta);
  42. Camera.transform.position = VecFunc(Timer, OnewayTime, PosOrigin, PosDelta);
  43. }
  44. else if (Phase == ZoomPhase.Bacward)
  45. {
  46. Camera.orthographicSize = SizeFunc(Timer, OnewayTime, SizeDestination, -SizeDelta);
  47. Camera.transform.position = VecFunc(Timer, OnewayTime, PosDestination, -PosDelta);
  48. }
  49. return false;
  50. }
  51. else
  52. {
  53. if (Phase == ZoomPhase.Forward)
  54. {
  55. Phase = ZoomPhase.Stay;
  56. Timer = 0;
  57. TempTime = Stay;
  58. Camera.orthographicSize = SizeDestination;
  59. Camera.transform.position = PosDestination;
  60. return false;
  61. }
  62. else if (Phase == ZoomPhase.Stay)
  63. {
  64. Phase = ZoomPhase.Bacward;
  65. Timer = 0;
  66. TempTime = OnewayTime;
  67. return false;
  68. }
  69. else if (Phase == ZoomPhase.Bacward)
  70. {
  71. Timer = 0;
  72. Camera.orthographicSize = SizeOrigin;
  73. Camera.transform.position = PosOrigin;
  74. OnForwardFinish.SafeInvoke();
  75. return true;
  76. }
  77. throw new Exception();
  78. }
  79. }
  80. public override bool DoBackward()
  81. {
  82. throw new Exception();
  83. }
  84. public void StartZoom(float sizeOrigin, float sizeDestination, float duration, float stay, Transform target, Curve curve)
  85. {
  86. OnForwardStart.SafeInvoke();
  87. Stay = stay;
  88. Duration = duration;
  89. OnewayTime = (duration - stay)/2;
  90. SizeDelta = sizeDestination - sizeOrigin;
  91. SizeOrigin = sizeOrigin;
  92. SizeDestination = sizeDestination;
  93. PosDelta = target.position - Camera.transform.position;
  94. PosOrigin = Camera.transform.position;
  95. PosDestination = target.position;
  96. PosDelta.z = 0;
  97. PosDestination.z = Camera.transform.position.z;
  98. Target = target;
  99. TempTime = OnewayTime;
  100. Phase = ZoomPhase.Forward;
  101. VecFunc = ManaAnim.CurveFuncDicV[curve];
  102. SizeFunc = ManaAnim.CurveFuncDicF[curve];
  103. ManaAnim.MoveForList.Remove(this);
  104. ManaAnim.MoveForList.Add(this);
  105. }
  106. }