TweenSr.cs 4.7 KB

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