TweenSr.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using UnityEngine;
  2. using System.Collections;
  3. public class TweenSr : Tween
  4. {
  5. #region 变量
  6. public override bool InOrigin
  7. {
  8. get
  9. {
  10. if (Target.color == Origin)
  11. {
  12. _InOrigin = true;
  13. }
  14. else
  15. {
  16. _InOrigin = false;
  17. }
  18. return _InOrigin;
  19. }
  20. set
  21. {
  22. _InOrigin = value;
  23. if (_InOrigin)
  24. {
  25. Target.color = Origin;
  26. }
  27. }
  28. }
  29. public override bool InDestination
  30. {
  31. get
  32. {
  33. if (Target.color == Destination)
  34. {
  35. _InDestination = true;
  36. }
  37. else
  38. {
  39. _InDestination = false;
  40. }
  41. return _InDestination;
  42. }
  43. set
  44. {
  45. _InDestination = value;
  46. if (_InDestination)
  47. {
  48. Target.color = Destination;
  49. }
  50. }
  51. }
  52. protected Color Delta;
  53. protected Color Origin;
  54. protected Color Destination;
  55. protected SpriteRenderer Target;
  56. protected CurveFunctionC Func;
  57. #endregion
  58. public TweenSr(SpriteRenderer target, Color origin, Color destination, float duration, bool originActive, bool destActive, Curve curve)
  59. {
  60. Func = ManaAnim.CurveFunctionDicC[curve];
  61. Target = target;
  62. InForward = false;
  63. InBackward = false;
  64. Delta = destination - origin;
  65. Origin = origin;
  66. Duration = duration;
  67. DestActive = destActive;
  68. Destination = destination;
  69. OriginActive = originActive;
  70. OnForwardStart += () =>
  71. {
  72. Target.SetActive(true);
  73. };
  74. OnForwardFinish += () =>
  75. {
  76. Target.SetActive(DestActive);
  77. };
  78. OnBackwardStart += () =>
  79. {
  80. Target.SetActive(true);
  81. };
  82. OnBackwardFinish += () =>
  83. {
  84. Target.SetActive(OriginActive);
  85. };
  86. }
  87. public override void StartForward()
  88. {
  89. base.StartForward();
  90. if (InBackward)
  91. {
  92. Timer = Duration - Timer;
  93. }
  94. else
  95. {
  96. Target.color = Origin;
  97. }
  98. }
  99. public override void StartBackward()
  100. {
  101. base.StartBackward();
  102. if (InForward)
  103. {
  104. Timer = Duration - Timer;
  105. }
  106. else
  107. {
  108. Target.color = Destination;
  109. }
  110. }
  111. public override bool DoForward()
  112. {
  113. Timer += Time.fixedDeltaTime;
  114. if (Timer > Duration)
  115. {
  116. Timer = 0;
  117. InForward = false;
  118. InDestination = true;
  119. OnForwardFinish.Invoke();
  120. ManaAnim.TweenForList.Remove(this);
  121. return true;
  122. }
  123. else
  124. {
  125. Target.color = Func(Timer, Duration, Origin, Delta);
  126. return false;
  127. }
  128. }
  129. public override bool DoBackward()
  130. {
  131. Timer += Time.fixedDeltaTime;
  132. if (Timer > Duration)
  133. {
  134. Timer = 0;
  135. InBackward = false;
  136. InOrigin = true;
  137. OnBackwardFinish.Invoke();
  138. ManaAnim.TweenBacList.Remove(this);
  139. return true;
  140. }
  141. else
  142. {
  143. Target.color = Func(Timer, Duration, Destination, new Color(-Delta.r, -Delta.g, -Delta.b, -Delta.a));
  144. return false;
  145. }
  146. }
  147. }