TweenRoot.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. using UnityEngine;
  2. using UnityEngine.Events;
  3. using System;
  4. using System.Collections;
  5. public abstract class TweenRoot : MoveRoot
  6. {
  7. public virtual bool InOrigin
  8. {
  9. get { return InOrigin_; }
  10. set { InOrigin_ = value; }
  11. }
  12. public bool InOrigin_;
  13. public bool CG;
  14. public bool Repeat;
  15. public bool PingPong;
  16. public bool InForward;
  17. public bool InBackward;
  18. public Curve Curve;
  19. public Component Component;
  20. public UnityAction OnBackwardStart;
  21. public UnityAction OnBackwardFinish;
  22. public CanvasGroup CanvasGroup;
  23. public float Duration;
  24. public float Timer;
  25. public bool DestActive;
  26. public bool OriginActive;
  27. public TweenRoot(bool cg, Curve curve, Component comp)
  28. {
  29. CG = cg;
  30. Curve = curve;
  31. Component = comp;
  32. if (cg)
  33. {
  34. CanvasGroup = comp.GetComponent<CanvasGroup>();
  35. }
  36. }
  37. public override void Pause()
  38. {
  39. if (!InPause)
  40. {
  41. InPause = true;
  42. if (InForward)
  43. {
  44. ManaAnim.MoveForList.Remove(this);
  45. }
  46. else if (InBackward)
  47. {
  48. ManaAnim.MoveBacList.Remove(this);
  49. }
  50. }
  51. }
  52. public override void Resume()
  53. {
  54. if (InPause)
  55. {
  56. InPause = false;
  57. if (InForward)
  58. {
  59. ManaAnim.MoveForList.Add(this);
  60. }
  61. else if (InBackward)
  62. {
  63. ManaAnim.MoveBacList.Add(this);
  64. }
  65. }
  66. }
  67. public void SetLoop(EventType eventType)
  68. {
  69. if (eventType == EventType.ForwardFinish)
  70. {
  71. if (Repeat)
  72. {
  73. ReForward();
  74. }
  75. else if (PingPong)
  76. {
  77. StartBackward();
  78. }
  79. }
  80. else if (eventType == EventType.BackwardFinish)
  81. {
  82. if (Repeat)
  83. {
  84. ReBackward();
  85. }
  86. else if (PingPong)
  87. {
  88. StartForward();
  89. }
  90. }
  91. }
  92. public virtual void ReForward()
  93. {
  94. Timer = 0;
  95. InOrigin = true;
  96. if (InForward)
  97. {
  98. InForward = false;
  99. ManaAnim.MoveForList.Remove(this);
  100. }
  101. if (InBackward)
  102. {
  103. InBackward = false;
  104. ManaAnim.MoveBacList.Remove(this);
  105. }
  106. StartForward();
  107. }
  108. public virtual void ReBackward()
  109. {
  110. Timer = 0;
  111. InDestination = true;
  112. if (InForward)
  113. {
  114. InForward = false;
  115. ManaAnim.MoveForList.Remove(this);
  116. }
  117. if (InBackward)
  118. {
  119. InBackward = false;
  120. ManaAnim.MoveBacList.Remove(this);
  121. }
  122. StartBackward();
  123. }
  124. public virtual bool StartForward()
  125. {
  126. InPause = false;
  127. if (InForward || InDestination)
  128. {
  129. return true;
  130. }
  131. Timer = 0;
  132. InForward = true;
  133. Component.SetActive(true);
  134. OnForwardStart.SafeInvoke();
  135. if (CG)
  136. {
  137. CanvasGroup.interactable = false;
  138. }
  139. if (InBackward)
  140. {
  141. ManaAnim.MoveBacList.Remove(this);
  142. }
  143. ManaAnim.MoveForList.Add(this);
  144. return false;
  145. }
  146. public virtual bool StartBackward()
  147. {
  148. InPause = false;
  149. if (InBackward || InOrigin)
  150. {
  151. return true;
  152. }
  153. Timer = 0;
  154. InBackward = true;
  155. Component.SetActive(true);
  156. OnBackwardStart.SafeInvoke();
  157. if (CG)
  158. {
  159. CanvasGroup.interactable = false;
  160. }
  161. if (InForward)
  162. {
  163. ManaAnim.MoveForList.Remove(this);
  164. }
  165. ManaAnim.MoveBacList.Add(this);
  166. return false;
  167. }
  168. public virtual void ForwardFinish()
  169. {
  170. Component.SetActive(DestActive);
  171. if (CG)
  172. {
  173. CanvasGroup.interactable = DestActive;
  174. }
  175. }
  176. public virtual void BackwardFinish()
  177. {
  178. Component.SetActive(OriginActive);
  179. if (CG)
  180. {
  181. CanvasGroup.interactable = OriginActive;
  182. }
  183. }
  184. public override void PushEvent(EventType type, UnityAction action)
  185. {
  186. if (type == EventType.ForwardStart)
  187. {
  188. OnForwardStart = action + OnForwardStart;
  189. }
  190. else if (type == EventType.ForwardFinish)
  191. {
  192. OnForwardFinish = action + OnForwardFinish;
  193. }
  194. else if (type == EventType.BackwardStart)
  195. {
  196. OnBackwardStart = action + OnBackwardStart;
  197. }
  198. else if (type == EventType.BackwardFinish)
  199. {
  200. OnBackwardFinish = action + OnBackwardFinish;
  201. }
  202. }
  203. public override void AddEventOnetime(EventType type, UnityAction action)
  204. {
  205. if (type == EventType.ForwardStart)
  206. {
  207. action += () =>
  208. {
  209. OnForwardStart -= action;
  210. };
  211. OnForwardStart += action;
  212. }
  213. else if (type == EventType.ForwardFinish)
  214. {
  215. action += () =>
  216. {
  217. OnForwardFinish -= action;
  218. };
  219. OnForwardFinish += action;
  220. }
  221. else if (type == EventType.BackwardStart)
  222. {
  223. action += () =>
  224. {
  225. OnBackwardStart -= action;
  226. };
  227. OnBackwardStart += action;
  228. }
  229. else if (type == EventType.BackwardFinish)
  230. {
  231. action += () =>
  232. {
  233. OnBackwardFinish -= action;
  234. };
  235. OnBackwardFinish += action;
  236. }
  237. }
  238. public override void PushEventOnetime(EventType type, UnityAction action)
  239. {
  240. if (type == EventType.ForwardStart)
  241. {
  242. action += () =>
  243. {
  244. OnForwardStart -= action;
  245. };
  246. OnForwardStart = action + OnForwardStart;
  247. }
  248. else if (type == EventType.ForwardFinish)
  249. {
  250. action += () =>
  251. {
  252. OnForwardFinish -= action;
  253. };
  254. OnForwardFinish = action + OnForwardFinish;
  255. }
  256. else if (type == EventType.BackwardStart)
  257. {
  258. action += () =>
  259. {
  260. OnBackwardStart -= action;
  261. };
  262. OnBackwardStart = action + OnBackwardStart;
  263. }
  264. else if (type == EventType.BackwardFinish)
  265. {
  266. action += () =>
  267. {
  268. OnBackwardFinish -= action;
  269. };
  270. OnBackwardFinish = action + OnBackwardFinish;
  271. }
  272. }
  273. }