StreamScale.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine.Events;
  7. public struct VecPair
  8. {
  9. public Vector3 Key;
  10. public Vector3 Value;
  11. public VecPair(Vector3 key, Vector3 value)
  12. {
  13. Key = key;
  14. Value = value;
  15. }
  16. public VecPair(float x1, float y1, float z1, float x2, float y2, float z2)
  17. {
  18. Key = new Vector3(x1, y1, z1);
  19. Value = new Vector3(x2, y2, z2);
  20. }
  21. }
  22. public class StreamScale : Tween
  23. {
  24. #region 变量
  25. public override bool InOrigin
  26. {
  27. get
  28. {
  29. if (Consecutive)
  30. {
  31. if (Target.localScale.Equal(DestList[0]))
  32. {
  33. _InOrigin = true;
  34. }
  35. else
  36. {
  37. _InOrigin = false;
  38. }
  39. }
  40. else
  41. {
  42. if (Target.localScale.Equal(DestKvList[0].Key))
  43. {
  44. _InOrigin = true;
  45. }
  46. else
  47. {
  48. _InOrigin = false;
  49. }
  50. }
  51. return _InOrigin;
  52. }
  53. set
  54. {
  55. _InOrigin = value;
  56. if (_InOrigin)
  57. {
  58. if (Consecutive)
  59. {
  60. Target.localScale = DestList[0];
  61. }
  62. else
  63. {
  64. Target.localScale = DestKvList[0].Key;
  65. }
  66. FinishBackward();
  67. }
  68. }
  69. }
  70. public override bool InDestination
  71. {
  72. get
  73. {
  74. if (Consecutive)
  75. {
  76. if (Target.localScale.Equal(DestList.Last(0)))
  77. {
  78. _InDestination = true;
  79. }
  80. else
  81. {
  82. _InDestination = false;
  83. }
  84. }
  85. else
  86. {
  87. if (Target.localScale.Equal(DestKvList.Last(0).Value))
  88. {
  89. _InDestination = true;
  90. }
  91. else
  92. {
  93. _InDestination = false;
  94. }
  95. }
  96. return _InDestination;
  97. }
  98. set
  99. {
  100. _InDestination = value;
  101. if (_InDestination)
  102. {
  103. if (Consecutive)
  104. {
  105. Target.localScale = DestList.Last(0);
  106. }
  107. else
  108. {
  109. Target.localScale = DestKvList.Last(0).Value;
  110. }
  111. FinishForward();
  112. }
  113. }
  114. }
  115. public int Phase;
  116. public int TotPhase;
  117. public bool Consecutive;
  118. public float TempDelay;
  119. public float TempDuration;
  120. public Vector3 TempDest;
  121. public Vector3 TempDelta;
  122. public Vector3 TempOrigin;
  123. public List<float> DelayList = new List<float>();
  124. public List<float> DurationList = new List<float>();
  125. public List<VecPair> DestKvList = new List<VecPair>();
  126. public List<Vector3> DestList = new List<Vector3>();
  127. public List<UnityAction> ActionList = new List<UnityAction>();
  128. public Transform Target;
  129. public CurveFunctionV Func;
  130. #endregion
  131. public StreamScale(Transform target, List<float> delayList, List<float> durationList, List<VecPair> destKvList, bool originActive, bool destActive, Curve curve, bool cg = false, List<UnityAction> actionList = null) : base(cg, curve, target)
  132. {
  133. Func = ManaAnim.CurveFuncDicV[curve];
  134. Target = target;
  135. TotPhase = destKvList.Count - 1;
  136. Consecutive = false;
  137. DelayList = delayList;
  138. ActionList = actionList;
  139. DestKvList = destKvList;
  140. DurationList = durationList;
  141. if (ActionList.Valid())
  142. {
  143. if (DestKvList.Count - ActionList.Count != -1)
  144. {
  145. throw new Exception();
  146. }
  147. }
  148. if (DestKvList.Count - DelayList.Count != 1)
  149. {
  150. throw new Exception();
  151. }
  152. if (DestKvList.Count - DurationList.Count != 0)
  153. {
  154. throw new Exception();
  155. }
  156. InForward = false;
  157. InBackward = false;
  158. DestActive = destActive;
  159. OriginActive = originActive;
  160. }
  161. public StreamScale(Transform target, List<float> delayList, List<float> durationList, List<Vector3> destList, bool originActive, bool destActive, Curve curve, bool cg = false, List<UnityAction> actionList = null) : base(cg, curve, target)
  162. {
  163. Func = ManaAnim.CurveFuncDicV[curve];
  164. Target = target;
  165. TotPhase = destList.Count - 1;
  166. Consecutive = true;
  167. DestList = destList;
  168. DelayList = delayList;
  169. ActionList = actionList;
  170. DurationList = durationList;
  171. if (ActionList.Valid())
  172. {
  173. if ((DestList.Count - 1) - ActionList.Count != -1)
  174. {
  175. throw new Exception();
  176. }
  177. }
  178. if (DestList.Count - DelayList.Count != 2)
  179. {
  180. throw new Exception();
  181. }
  182. if (DestList.Count - DurationList.Count != 1)
  183. {
  184. throw new Exception();
  185. }
  186. InForward = false;
  187. InBackward = false;
  188. DestActive = destActive;
  189. OriginActive = originActive;
  190. }
  191. public override void StartForward()
  192. {
  193. base.StartForward();
  194. if (Consecutive)
  195. {
  196. Phase = 1;
  197. TempDest = DestList[1];
  198. TempDelay = DelayList[0];
  199. TempOrigin = DestList[0];
  200. TempDuration = DurationList[0];
  201. }
  202. else
  203. {
  204. Phase = 0;
  205. TempDest = DestKvList[0].Value;
  206. TempDelay = DelayList[0];
  207. TempOrigin = DestKvList[0].Key;
  208. TempDuration = DurationList[0];
  209. }
  210. TempDelta = TempDest - TempOrigin;
  211. if (ActionList.Valid())
  212. {
  213. ActionList[0].SafeInvoke();
  214. }
  215. //if (InBackward)
  216. //{
  217. // Timer = ManaAnim.GetTimerFloat(Target.fontSize, Duration, TempOrigin, TempDelta, Curve);
  218. //}
  219. }
  220. public override void StartBackward()
  221. {
  222. base.StartBackward();
  223. throw new Exception();
  224. }
  225. public override bool DoForward()
  226. {
  227. Timer += Time.fixedDeltaTime;
  228. if (Phase == TotPhase)
  229. {
  230. if (Timer > TempDuration)
  231. {
  232. FinishForward();
  233. Timer = 0;
  234. InForward = false;
  235. InDestination = true;
  236. if (OnForwardFinish != null)
  237. {
  238. OnForwardFinish.Invoke();
  239. }
  240. if (ActionList.Valid())
  241. {
  242. ActionList.Last(0).SafeInvoke();
  243. }
  244. return true;
  245. }
  246. else
  247. {
  248. Target.localScale = Func(Timer, TempDuration, TempOrigin, TempDelta);
  249. return false;
  250. }
  251. }
  252. else
  253. {
  254. if (Timer > TempDuration + TempDelay)
  255. {
  256. Timer = 0;
  257. Phase++;
  258. if (Consecutive)
  259. {
  260. TempDest = DestList[Phase];
  261. TempOrigin = DestList[Phase - 1];
  262. TempDuration = DurationList[Phase - 1];
  263. TempDelta = TempDest - TempOrigin;
  264. if (Phase != DestList.Count - 1)
  265. {
  266. TempDelay = DelayList[Phase - 1];
  267. }
  268. if (ActionList.Valid())
  269. {
  270. ActionList[Phase - 1].SafeInvoke();
  271. }
  272. }
  273. else
  274. {
  275. TempDest = DestKvList[Phase].Value;
  276. TempOrigin = DestKvList[Phase].Key;
  277. TempDuration = DurationList[Phase];
  278. TempDelta = TempDest - TempOrigin;
  279. if (Phase != DestKvList.Count - 1)
  280. {
  281. TempDelay = DelayList[Phase];
  282. }
  283. if (ActionList.Valid())
  284. {
  285. ActionList[Phase].SafeInvoke();
  286. }
  287. }
  288. return false;
  289. }
  290. else
  291. {
  292. Target.localScale = Func(Timer, TempDuration, TempOrigin, TempDelta);
  293. return false;
  294. }
  295. }
  296. }
  297. public override bool DoBackward()
  298. {
  299. throw new Exception();
  300. }
  301. }