TweenSr.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. using UnityEngine;
  2. using System.Linq;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. public class TweenSr : Tween
  6. {
  7. #region 变量
  8. public override bool InOrigin
  9. {
  10. get
  11. {
  12. if (Target.color.Equal(Origin))
  13. {
  14. _InOrigin = true;
  15. }
  16. else
  17. {
  18. _InOrigin = false;
  19. }
  20. return _InOrigin;
  21. }
  22. set
  23. {
  24. _InOrigin = value;
  25. if (_InOrigin)
  26. {
  27. Target.color = Origin;
  28. if (Group)
  29. {
  30. for (int i = 0; i < ChildList.Count; i++)
  31. {
  32. if (ChildList[i].transform.parent != Target.transform)
  33. {
  34. ChildList.RemoveAt(i--);
  35. continue;
  36. }
  37. Color selfColor = ColorDic[ChildList[i]];
  38. ChildList[i].material.SetColor("_Color", selfColor * Target.color);
  39. }
  40. }
  41. BackwardFinish();
  42. }
  43. }
  44. }
  45. public override bool InDestination
  46. {
  47. get
  48. {
  49. if (Target.color.Equal(Destination))
  50. {
  51. _InDestination = true;
  52. }
  53. else
  54. {
  55. _InDestination = false;
  56. }
  57. return _InDestination;
  58. }
  59. set
  60. {
  61. _InDestination = value;
  62. if (_InDestination)
  63. {
  64. Target.color = Destination;
  65. if (Group)
  66. {
  67. for (int i = 0; i < ChildList.Count; i++)
  68. {
  69. if (ChildList[i].transform.parent != Target.transform)
  70. {
  71. ChildList.RemoveAt(i--);
  72. continue;
  73. }
  74. Color selfColor = ColorDic[ChildList[i]];
  75. ChildList[i].material.SetColor("_Color", selfColor * Target.color);
  76. }
  77. }
  78. ForwardFinish();
  79. }
  80. }
  81. }
  82. public bool Group;
  83. public Color Delta;
  84. public Color Origin;
  85. public Color Destination;
  86. public SpriteRenderer Target;
  87. public CurveFunctionC Func;
  88. public List<Renderer> ChildList;
  89. public Dictionary<Renderer, Color> ColorDic = new Dictionary<Renderer, Color>();
  90. #endregion
  91. public TweenSr(SpriteRenderer target, Color origin, Color destination, float duration, bool originActive, bool destActive, Curve curve,bool cg = false,bool group=false) : base(cg, curve, target)
  92. {
  93. Func = ManaAnim.CurveFuncDicC[curve];
  94. Target = target;
  95. InForward = false;
  96. InBackward = false;
  97. Delta = destination - origin;
  98. Origin = origin;
  99. Group = group;
  100. Duration = duration;
  101. DestActive = destActive;
  102. Destination = destination;
  103. OriginActive = originActive;
  104. }
  105. public override void StartForward()
  106. {
  107. base.StartForward();
  108. if (Group)
  109. {
  110. Renderer[] renderers = Target.GetComponentsInChildren<Renderer>();
  111. ChildList = new List<Renderer>();
  112. for (int i = 1; i < renderers.Length; i++)
  113. {
  114. Renderer renderer = renderers[i];
  115. ChildList.Add(renderer);
  116. if (!ColorDic.ContainsKey(renderer))
  117. {
  118. ColorDic.Add(renderer, renderer.material.GetColor("_Color"));
  119. }
  120. }
  121. List<Renderer> keyList = ColorDic.Keys.ToList();
  122. for (int i = 0; i < keyList.Count; i++)
  123. {
  124. if (!ChildList.Contains(keyList[i]))
  125. {
  126. ColorDic.Remove(keyList[i]);
  127. }
  128. }
  129. }
  130. if (InBackward)
  131. {
  132. Timer = ManaAnim.GetTimerColor(Target.color, Duration, Origin, Delta, Curve);
  133. }
  134. }
  135. public override void StartBackward()
  136. {
  137. base.StartBackward();
  138. if (Group)
  139. {
  140. Renderer[] renderers = Target.GetComponentsInChildren<Renderer>();
  141. ChildList = new List<Renderer>();
  142. for (int i = 1; i < renderers.Length; i++)
  143. {
  144. Renderer renderer = renderers[i];
  145. ChildList.Add(renderer);
  146. if (!ColorDic.ContainsKey(renderer))
  147. {
  148. ColorDic.Add(renderer, renderer.material.GetColor("_Color"));
  149. }
  150. }
  151. List<Renderer> keyList = ColorDic.Keys.ToList();
  152. for (int i = 0; i < keyList.Count; i++)
  153. {
  154. if (!ChildList.Contains(keyList[i]))
  155. {
  156. ColorDic.Remove(keyList[i]);
  157. }
  158. }
  159. }
  160. if (InForward)
  161. {
  162. Timer = ManaAnim.GetTimerColor(Target.color, Duration, Destination, new Color(-Delta.r, -Delta.g, -Delta.b, -Delta.a), Curve);
  163. }
  164. }
  165. public override bool DoForward()
  166. {
  167. Timer += Time.fixedDeltaTime;
  168. if (Timer > Duration)
  169. {
  170. InForward = false;
  171. InDestination = true;
  172. if (OnForwardFinish != null)
  173. {
  174. OnForwardFinish.Invoke();
  175. }
  176. return true;
  177. }
  178. else
  179. {
  180. Target.color = Func(Timer, Duration, Origin, Delta);
  181. if (Group)
  182. {
  183. for (int i = 0; i < ChildList.Count; i++)
  184. {
  185. if (ChildList[i].transform.parent != Target.transform)
  186. {
  187. ChildList.RemoveAt(i--);
  188. continue;
  189. }
  190. Color selfColor = ColorDic[ChildList[i]];
  191. ChildList[i].material.SetColor("_Color", selfColor * Target.color);
  192. }
  193. }
  194. return false;
  195. }
  196. }
  197. public override bool DoBackward()
  198. {
  199. Timer += Time.fixedDeltaTime;
  200. if (Timer > Duration)
  201. {
  202. InBackward = false;
  203. InOrigin = true;
  204. if (OnBackwardFinish != null)
  205. {
  206. OnBackwardFinish.Invoke();
  207. }
  208. return true;
  209. }
  210. else
  211. {
  212. Target.color = Func(Timer, Duration, Destination, new Color(-Delta.r, -Delta.g, -Delta.b, -Delta.a));
  213. if (Group)
  214. {
  215. for (int i = 0; i < ChildList.Count; i++)
  216. {
  217. if (ChildList[i].transform.parent != Target.transform)
  218. {
  219. ChildList.RemoveAt(i--);
  220. continue;
  221. }
  222. Color selfColor = ColorDic[ChildList[i]];
  223. ChildList[i].material.SetColor("_Color", selfColor * Target.color);
  224. }
  225. }
  226. return false;
  227. }
  228. }
  229. }