TweenSr.cs 4.7 KB

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