TimeLineEventParticleLogicBasic.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Common.Utility.CombatTimer;
  4. using Fort23.Core;
  5. #if !COMBAT_SERVER
  6. using Fort23.Core;
  7. #endif
  8. using Fort23.UTool;
  9. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
  10. #if !COMBAT_SERVER
  11. using UnityEngine;
  12. #endif
  13. namespace UTool.CustomizeTimeLogic.FxLogic.TimeLineEventLogic
  14. {
  15. public class TimeLineEventParticleLogicBasic : TimeLineEventLogicBasic
  16. {
  17. // private Timer timer;
  18. private BetterList<Clock> loadTask = new BetterList<Clock>();
  19. // private BetterList<string> long = new BetterList<Clock>();
  20. public BetterList<ParticleSystemPool> loopFx = new BetterList<ParticleSystemPool>();
  21. public BetterList<ParticleSystemPool> _allLoadFx = new BetterList<ParticleSystemPool>();
  22. private CombatTimer _combatTimer;
  23. private int _loadCount;
  24. public TimeLinePlayFxSerializtion timeLinePlayFxSerializtion
  25. {
  26. get { return mTimeLineAssetSerialization as TimeLinePlayFxSerializtion; }
  27. }
  28. protected override void ProDormancyObj()
  29. {
  30. loopFx.Clear();
  31. _allLoadFx.Clear();
  32. loadTask.Clear();
  33. CombatTimerManager.Instance.RemoveTimer(_combatTimer);
  34. _combatTimer = null;
  35. }
  36. protected override void ProSetCombatInfo()
  37. {
  38. }
  39. protected override void ProEnter()
  40. {
  41. // ITimeLineTriggerEvent trigger = _targetEntity as ITimeLineTriggerEvent;
  42. // if (trigger != null)
  43. {
  44. BetterList<ILifetCycleHitPoint> timeLineEntities = GetSkillTarget();
  45. ExecuteFxTarget(timeLineEntities, 0);
  46. }
  47. }
  48. protected override void ProLeave()
  49. {
  50. }
  51. protected override void ProTimeUpdate()
  52. {
  53. }
  54. protected override void ProBreakTimeLine()
  55. {
  56. for (int i = 0; i < loadTask.Count; i++)
  57. {
  58. loadTask[i].Dispose();
  59. }
  60. CombatTimerManager.Instance.RemoveTimer(_combatTimer);
  61. _combatTimer = null;
  62. CloseLoopFx();
  63. loadTask.Clear();
  64. }
  65. public override bool IsFinish()
  66. {
  67. return _allLoadFx.Count <= 0 && _loadCount <= 0;
  68. }
  69. public void CloseLoopFx()
  70. {
  71. if (loopFx.Count <= 0)
  72. {
  73. return;
  74. }
  75. ParticleSystemPool[] pool = loopFx.ToArray();
  76. for (int i = 0; i < pool.Length; i++)
  77. {
  78. GObjectPool.Instance.Recycle(pool[i]);
  79. }
  80. loopFx.Clear();
  81. }
  82. public void CloseAllFx()
  83. {
  84. if (_allLoadFx.Count <= 0)
  85. {
  86. return;
  87. }
  88. ParticleSystemPool[] pool = _allLoadFx.ToArray();
  89. for (int i = 0; i < pool.Length; i++)
  90. {
  91. GObjectPool.Instance.Recycle(pool[i]);
  92. }
  93. _allLoadFx.Clear();
  94. }
  95. protected override void ProDispose()
  96. {
  97. for (int i = 0; i < loadTask.Count; i++)
  98. {
  99. loadTask[i].Dispose();
  100. }
  101. CombatTimerManager.Instance.RemoveTimer(_combatTimer);
  102. _combatTimer = null;
  103. loadTask.Clear();
  104. if (currTarget != null)
  105. {
  106. currTarget.Dispose();
  107. }
  108. currTarget = null;
  109. CloseAllFx();
  110. loopFx.Clear();
  111. _allLoadFx.Clear();
  112. }
  113. private void ExecuteFxTarget(BetterList<ILifetCycleHitPoint> combatTarget, int index)
  114. {
  115. if (combatTarget.Count <= index)
  116. {
  117. return;
  118. }
  119. ILifetCycleHitPoint lifeCycle = combatTarget[index];
  120. if (lifeCycle == null)
  121. {
  122. // LogTool.Log("一个空的目标");
  123. index++;
  124. ExecuteFxTarget(combatTarget, index);
  125. return;
  126. }
  127. if (!string.IsNullOrEmpty(timeLinePlayFxSerializtion.fxName))
  128. {
  129. ILifetCycleHitPoint fxTarget = null;
  130. Vector3 startPos = Vector3.one;
  131. SpecialDotInfo targetSpecialDotInfo = null;
  132. switch (timeLinePlayFxSerializtion.locationType)
  133. {
  134. case FXLocationType.Oneself:
  135. fxTarget = _castEntity.GetMainHotPoin<ILifetCycleHitPoint>(true);
  136. break;
  137. case FXLocationType.Target:
  138. fxTarget = lifeCycle;
  139. break;
  140. case FXLocationType.CustomTarget:
  141. fxTarget = lifeCycle;
  142. break;
  143. case FXLocationType.SceneZero:
  144. fxTarget = _castEntity.GetMainHotPoin<ILifetCycleHitPoint>(false);
  145. startPos = TimeLineEventLogicGroup.SceneWorldPos();
  146. break;
  147. case FXLocationType.OneselfSpecialDot:
  148. fxTarget = _castEntity.GetMainHotPoin<ILifetCycleHitPoint>(false);
  149. break;
  150. case FXLocationType.TargetSpecialDot:
  151. fxTarget = lifeCycle;
  152. break;
  153. }
  154. if (fxTarget != null)
  155. {
  156. if (!string.IsNullOrEmpty(timeLinePlayFxSerializtion.hitPointGroupName))
  157. {
  158. ILifetCycleHitPoint newHitPoint =
  159. fxTarget.IfLifeCycle.GetILifetCycleHitPoint<ILifetCycleHitPoint>(
  160. timeLinePlayFxSerializtion.hitPointGroupName, true, true);
  161. targetSpecialDotInfo =
  162. newHitPoint.GetSpecialDotInfo(timeLinePlayFxSerializtion.targetSpecialDotName);
  163. }
  164. else
  165. {
  166. targetSpecialDotInfo =
  167. fxTarget.GetSpecialDotInfo(timeLinePlayFxSerializtion.targetSpecialDotName);
  168. }
  169. }
  170. if (timeLinePlayFxSerializtion.isActivityCustomTargetPos && customizePos != null &&
  171. customizePos.Length > timeLinePlayFxSerializtion.CustomTargetPosIndex)
  172. {
  173. startPos = customizePos[timeLinePlayFxSerializtion.CustomTargetPosIndex];
  174. targetSpecialDotInfo = null;
  175. }
  176. else if (targetSpecialDotInfo != null &&
  177. timeLinePlayFxSerializtion.locationType != FXLocationType.SceneZero)
  178. {
  179. startPos = targetSpecialDotInfo.GetWorlPos();
  180. }
  181. if (timeLinePlayFxSerializtion.isGround)
  182. {
  183. startPos = new Vector3(startPos.x, (float)0.7f);
  184. }
  185. LoadFx(lifeCycle, fxTarget, startPos, targetSpecialDotInfo);
  186. }
  187. index++;
  188. if (timeLinePlayFxSerializtion.intervalTime > 0)
  189. {
  190. _combatTimer = CombatTimerManager.Instance.AddTimer(
  191. (float)timeLinePlayFxSerializtion.intervalTime * index,
  192. delegate { });
  193. ExecuteFxTarget(combatTarget, index);
  194. }
  195. else
  196. {
  197. ExecuteFxTarget(combatTarget, index);
  198. }
  199. }
  200. protected void ParticleSystemPoolEndFx(ParticleSystemPool particleSystemPool)
  201. {
  202. loopFx.Remove(particleSystemPool);
  203. _allLoadFx.Remove(particleSystemPool);
  204. }
  205. protected void LoadFx(ILifetCycleHitPoint effectTarget, ILifetCycleHitPoint fxTarget, Vector3 startPos,
  206. SpecialDotInfo targetSpecialDotInfo)
  207. {
  208. ITimeLineParticleFactory iTimeLineParticleFactory =
  209. TimeLineFxParticleTool.Instance.TimeLineFxParticleFactory;
  210. if (iTimeLineParticleFactory != null)
  211. {
  212. _loadCount++;
  213. Clock clock = iTimeLineParticleFactory.CreateParticle(this, effectTarget, fxTarget, startPos,
  214. targetSpecialDotInfo,
  215. delegate(IGObjectPoolInterface systemPool)
  216. {
  217. _loadCount--;
  218. ParticleSystemPool pool = systemPool as ParticleSystemPool;
  219. if (pool != null)
  220. {
  221. if (IsDis)
  222. {
  223. GObjectPool.Instance.Recycle(pool);
  224. return;
  225. }
  226. pool.OnEndFx = ParticleSystemPoolEndFx;
  227. if (timeLinePlayFxSerializtion.isLoop)
  228. {
  229. loopFx.Add(pool);
  230. }
  231. _allLoadFx.Add(pool);
  232. if (timeLinePlayFxSerializtion.isAttSpeed)
  233. {
  234. ITimeLineParticlePlaySpeed timeLineParticlePlaySpeed =
  235. _castEntity as ITimeLineParticlePlaySpeed;
  236. #if !COMBAT_SERVER
  237. pool.palySpeed = timeLineParticlePlaySpeed.GetCurrPlaySpeed(timeLinePlayFxSerializtion);
  238. #endif
  239. }
  240. else
  241. {
  242. #if !COMBAT_SERVER
  243. pool.palySpeed = (float)1;
  244. #endif
  245. }
  246. _timeLineEventLogicGroup.OnInitParticleSystemPoolCallBack?.Invoke(pool);
  247. }
  248. });
  249. if (clock != null)
  250. {
  251. loadTask.Add(clock);
  252. }
  253. }
  254. }
  255. }
  256. }