TweenSr.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. if (Group)
  27. {
  28. for (int i = 0; i < Targets.Length; i++)
  29. {
  30. Targets[i].SetAlpha(Target.color.a * Targets[i].color.a);
  31. }
  32. }
  33. Target.SetActive(OriginActive);
  34. }
  35. }
  36. }
  37. public override bool InDestination
  38. {
  39. get
  40. {
  41. if (Target.color == Destination)
  42. {
  43. _InDestination = true;
  44. }
  45. else
  46. {
  47. _InDestination = false;
  48. }
  49. return _InDestination;
  50. }
  51. set
  52. {
  53. _InDestination = value;
  54. if (_InDestination)
  55. {
  56. Target.color = Destination;
  57. if (Group)
  58. {
  59. for (int i = 0; i < Targets.Length; i++)
  60. {
  61. Targets[i].SetAlpha(Target.color.a * Targets[i].color.a);
  62. }
  63. }
  64. Target.SetActive(DestActive);
  65. }
  66. }
  67. }
  68. protected bool Group;
  69. protected Color Delta;
  70. protected Color Origin;
  71. protected Color Destination;
  72. protected SpriteRenderer Target;
  73. protected SpriteRenderer[] Targets;
  74. protected CurveFunctionC Func;
  75. #endregion
  76. public TweenSr(SpriteRenderer target, Color origin, Color destination, float duration, bool group, bool originActive, bool destActive, Curve curve)
  77. {
  78. Func = ManaAnim.CurveFuncDicC[curve];
  79. Target = target;
  80. InForward = false;
  81. InBackward = false;
  82. Delta = destination - origin;
  83. Origin = origin;
  84. Group = group;
  85. Duration = duration;
  86. DestActive = destActive;
  87. Destination = destination;
  88. OriginActive = originActive;
  89. }
  90. public override void StartForward()
  91. {
  92. base.StartForward();
  93. Target.SetActive(true);
  94. if (Group)
  95. {
  96. Targets = Target.GetComponentsInChildren<SpriteRenderer>();
  97. }
  98. if (InBackward)
  99. {
  100. Timer = Duration - Timer;
  101. }
  102. else
  103. {
  104. Target.color = Origin;
  105. }
  106. }
  107. public override void StartBackward()
  108. {
  109. base.StartBackward();
  110. Target.SetActive(true);
  111. if (Group)
  112. {
  113. Targets = Target.GetComponentsInChildren<SpriteRenderer>();
  114. }
  115. if (InForward)
  116. {
  117. Timer = Duration - Timer;
  118. }
  119. else
  120. {
  121. Target.color = Destination;
  122. }
  123. }
  124. public override bool DoForward()
  125. {
  126. Timer += Time.fixedDeltaTime;
  127. if (Timer > Duration)
  128. {
  129. Timer = 0;
  130. InForward = false;
  131. InDestination = true;
  132. if (OnForwardFinish != null)
  133. {
  134. OnForwardFinish.Invoke();
  135. }
  136. ManaAnim.TweenForList.Remove(this);
  137. return true;
  138. }
  139. else
  140. {
  141. Target.color = Func(Timer, Duration, Origin, Delta);
  142. if (Group)
  143. {
  144. for (int i = 0; i < Targets.Length; i++)
  145. {
  146. Targets[i].SetAlpha(Target.color.a * Targets[i].color.a);
  147. }
  148. }
  149. return false;
  150. }
  151. }
  152. public override bool DoBackward()
  153. {
  154. Timer += Time.fixedDeltaTime;
  155. if (Timer > Duration)
  156. {
  157. Timer = 0;
  158. InBackward = false;
  159. InOrigin = true;
  160. if (OnBackwardFinish != null)
  161. {
  162. OnBackwardFinish.Invoke();
  163. }
  164. ManaAnim.TweenBacList.Remove(this);
  165. return true;
  166. }
  167. else
  168. {
  169. Target.color = Func(Timer, Duration, Destination, new Color(-Delta.r, -Delta.g, -Delta.b, -Delta.a));
  170. if (Group)
  171. {
  172. for (int i = 0; i < Targets.Length; i++)
  173. {
  174. Targets[i].SetAlpha(Target.color.a * Targets[i].color.a);
  175. }
  176. }
  177. return false;
  178. }
  179. }
  180. }