GameTimeLineParticleFactory.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using Common.Combat.FxAILogic;
  5. using Fort23.Common;
  6. using Fort23.Core;
  7. using Fort23.UTool;
  8. using GameLogic.Combat.CombatTool;
  9. using GameLogic.Combat.Hero;
  10. using UnityEngine;
  11. using UnityEngine.Rendering;
  12. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
  13. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventLogic;
  14. public class GameTimeLineParticleFactory : ITimeLineParticleFactory
  15. {
  16. protected BetterList<CombatParticleSystemPool> allCombatParticleSystem =
  17. new BetterList<CombatParticleSystemPool>();
  18. protected BetterList<FxAILogicBasic> allFxAiLogicBasic = new BetterList<FxAILogicBasic>();
  19. protected bool _isUpdateState;
  20. private BetterList<FxAILogicBasic> _removeFxAiLogicBasic = new BetterList<FxAILogicBasic>();
  21. public void RemoveFxAILogicBasic(FxAILogicBasic fxAILogicBasic)
  22. {
  23. if (_isUpdateState)
  24. {
  25. _removeFxAiLogicBasic.Add(fxAILogicBasic);
  26. }
  27. else
  28. {
  29. allFxAiLogicBasic.Remove(fxAILogicBasic);
  30. }
  31. }
  32. public void CombatUpdate(float time)
  33. {
  34. _isUpdateState = true;
  35. for (int i = 0; i < allFxAiLogicBasic.Count; i++)
  36. {
  37. allFxAiLogicBasic[i].CombatUpdate(time);
  38. }
  39. _isUpdateState = false;
  40. for (int i = 0; i < _removeFxAiLogicBasic.Count; i++)
  41. {
  42. allFxAiLogicBasic.Remove(_removeFxAiLogicBasic[i]);
  43. }
  44. _removeFxAiLogicBasic.Clear();
  45. for (int i = 0; i < allCombatParticleSystem.Count; i++)
  46. {
  47. allCombatParticleSystem[i].CombatUpdate(time);
  48. }
  49. }
  50. public void Dispose()
  51. {
  52. allFxAiLogicBasic.Clear();
  53. }
  54. public void RecycleAllFxAiLogicBasic()
  55. {
  56. _isUpdateState = true;
  57. for (int i = 0; i < allFxAiLogicBasic.Count; i++)
  58. {
  59. allFxAiLogicBasic[i].Dispose();
  60. }
  61. allFxAiLogicBasic.Clear();
  62. _removeFxAiLogicBasic.Clear();
  63. _isUpdateState = false;
  64. }
  65. public void RecycleFix()
  66. {
  67. #if !COMBAT_SERVER
  68. CombatParticleSystemPool[] pools = allCombatParticleSystem.ToArray();
  69. if (pools != null)
  70. {
  71. List<CombatParticleSystemPool> romvePoll = new List<CombatParticleSystemPool>();
  72. romvePoll.AddRange(pools);
  73. for (int i = 0; i < romvePoll.Count; i++)
  74. {
  75. if (pools[i] == null)
  76. {
  77. continue;
  78. }
  79. if (pools[i].gameObject != null)
  80. {
  81. pools[i].gameObject.SetActive(false);
  82. GObjectPool.Instance.Recycle(pools[i]);
  83. }
  84. }
  85. }
  86. #endif
  87. allCombatParticleSystem.Clear();
  88. }
  89. public void RemoveCombatParticleSystemPool(CombatParticleSystemPool combatParticleSystemPool)
  90. {
  91. allCombatParticleSystem.Remove(combatParticleSystemPool);
  92. }
  93. public Clock CreateParticle(TimeLineEventParticleLogicBasic timeLineEventParticleLogicBasic,
  94. ILifetCycleHitPoint effectTarget,
  95. ILifetCycleHitPoint fxTarget, Vector3 startPos, SpecialDotInfo targetSpecialDotInfo,
  96. Action<IGObjectPoolInterface> callBack)
  97. {
  98. Clock clock = CreateParticle(timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.fxName, startPos,
  99. fxTarget,
  100. false, targetSpecialDotInfo, delegate(ParticleSystemPool combatParticleSystemPool)
  101. {
  102. CombatParticleSystemPool pool = combatParticleSystemPool as CombatParticleSystemPool;
  103. if (pool == null)
  104. {
  105. callBack?.Invoke(null);
  106. return;
  107. }
  108. #if !COMBAT_SERVER
  109. pool.InitCombatParticleSystem();
  110. #endif
  111. CombatHeroEntity combatHeroEntity = null;
  112. if (targetSpecialDotInfo != null)
  113. {
  114. combatHeroEntity = targetSpecialDotInfo.heroEntity as CombatHeroEntity;
  115. // if (!timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isActivityCustomTargetPos)
  116. // {
  117. // startPos = targetSpecialDotInfo.GetWorlPos();
  118. // }
  119. if (!timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isNotRotate)
  120. {
  121. pool.transform.eulerAngles = targetSpecialDotInfo.GetEulerAngles();
  122. pool.isNotRotion = false;
  123. }
  124. else
  125. {
  126. pool.isNotRotion = true;
  127. }
  128. // if (heroEntity != null)
  129. // {
  130. // pool.transform.SetParent(heroEntity.CombatHeroTransform.iGObjectPoolInterface.own.transform);
  131. // }
  132. // else
  133. // {
  134. // pool.transform.SetParent(targetSpecialDotInfo.targetTran);
  135. // }
  136. }
  137. if (combatHeroEntity != null && timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isLoop)
  138. {
  139. combatHeroEntity.heroLoopParticle.Add(pool);
  140. pool.HeroEntity = combatHeroEntity;
  141. }
  142. pool.gameObject.SetActive(false);
  143. pool.transform.position = startPos;
  144. if (timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isFollowRootTarget &&
  145. timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.locationType !=
  146. FXLocationType.SceneZero)
  147. {
  148. if (combatHeroEntity != null)
  149. {
  150. pool.transform.SetParent(combatHeroEntity.GetMainHotPoin<CombatHeroHitPoint>()
  151. .GetSpecialDotInfo("").targetTran);
  152. }
  153. else if (fxTarget != null)
  154. {
  155. pool.transform.SetParent(fxTarget
  156. .GetSpecialDotInfo("").targetTran);
  157. }
  158. pool.transform.localEulerAngles = Vector3.zero;
  159. }
  160. else if (timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isFollowTarget &&
  161. timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.locationType !=
  162. FXLocationType.SceneZero)
  163. {
  164. pool.transform.SetParent(targetSpecialDotInfo.targetTran);
  165. pool.transform.localEulerAngles = Vector3.zero;
  166. pool.transform.localPosition = Vector3.zero;
  167. // pool.targetSpecialDotInfo = targetSpecialDotInfo;
  168. }
  169. else
  170. {
  171. // pool.transform.SetParent(null);
  172. pool.targetSpecialDotInfo = null;
  173. }
  174. FxAILogicBasic fxAILogicBasic = pool.own.GetComponent<FxAILogicBasic>();
  175. if (fxAILogicBasic != null)
  176. {
  177. if (!allFxAiLogicBasic.Contains(fxAILogicBasic))
  178. {
  179. allFxAiLogicBasic.Add(fxAILogicBasic);
  180. }
  181. fxAILogicBasic.SetAIMonoObj(combatParticleSystemPool);
  182. fxAILogicBasic.Init(startPos, timeLineEventParticleLogicBasic, effectTarget,
  183. targetSpecialDotInfo);
  184. }
  185. #if !COMBAT_SERVER
  186. pool.gameObject.SetActive(true);
  187. #endif
  188. callBack?.Invoke(combatParticleSystemPool);
  189. });
  190. return clock;
  191. }
  192. public Clock CreateParticle(string fxName, Vector3 startPos, ILifetCycleHitPoint fxTarget, bool isRotate,
  193. SpecialDotInfo targetSpecialDotInfo, Action<ParticleSystemPool> callBack)
  194. {
  195. #if !COMBAT_SERVER
  196. Clock clock = ClockPool.GetClock();
  197. CTask<CombatParticleSystemPool> task = GObjectPool.Instance.FetchAsync(fxName + ".prefab",
  198. delegate(CombatParticleSystemPool pool)
  199. {
  200. if (pool == null)
  201. {
  202. callBack?.Invoke(null);
  203. return;
  204. }
  205. if (isRotate && fxTarget != null)
  206. {
  207. SpecialDotInfo specialDotInfo = fxTarget.GetSpecialDotInfo(null);
  208. if (specialDotInfo != null)
  209. {
  210. pool.transform.eulerAngles = specialDotInfo.GetEulerAngles();
  211. }
  212. }
  213. float size = 1;
  214. pool.SetSize(size);
  215. pool.own.transform.position = startPos;
  216. pool.ClearTrail();
  217. callBack?.Invoke(pool);
  218. }, clock);
  219. return clock;
  220. #else
  221. callBack?.Invoke(new CombatParticleSystemPool());
  222. return null;
  223. #endif
  224. }
  225. }