GameTimeLineParticleFactory.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. }else if (fxTarget != null)
  137. {
  138. if (!timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isNotRotate)
  139. {
  140. pool.transform.eulerAngles = fxTarget.GetSpecialDotInfo("").GetEulerAngles();
  141. pool.isNotRotion = false;
  142. }
  143. else
  144. {
  145. pool.isNotRotion = true;
  146. }
  147. }
  148. if (combatHeroEntity != null && timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isLoop)
  149. {
  150. combatHeroEntity.heroLoopParticle.Add(pool);
  151. pool.HeroEntity = combatHeroEntity;
  152. }
  153. pool.gameObject.SetActive(false);
  154. pool.transform.position = startPos;
  155. if (timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isFollowRootTarget &&
  156. timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.locationType !=
  157. FXLocationType.SceneZero)
  158. {
  159. if (combatHeroEntity != null)
  160. {
  161. pool.transform.SetParent(combatHeroEntity.GetMainHotPoin<CombatHeroHitPoint>()
  162. .GetSpecialDotInfo("").targetTran);
  163. }
  164. else if (fxTarget != null)
  165. {
  166. pool.transform.SetParent(fxTarget
  167. .GetSpecialDotInfo("").targetTran);
  168. }
  169. pool.transform.localEulerAngles = Vector3.zero;
  170. }
  171. else if (timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isFollowTarget &&
  172. timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.locationType !=
  173. FXLocationType.SceneZero)
  174. {
  175. pool.transform.SetParent(targetSpecialDotInfo.targetTran);
  176. pool.transform.localEulerAngles = Vector3.zero;
  177. pool.transform.localPosition = Vector3.zero;
  178. // pool.targetSpecialDotInfo = targetSpecialDotInfo;
  179. }
  180. else
  181. {
  182. // pool.transform.SetParent(null);
  183. pool.targetSpecialDotInfo = null;
  184. }
  185. FxAILogicBasic fxAILogicBasic = pool.own.GetComponent<FxAILogicBasic>();
  186. if (fxAILogicBasic != null)
  187. {
  188. if (!allFxAiLogicBasic.Contains(fxAILogicBasic))
  189. {
  190. allFxAiLogicBasic.Add(fxAILogicBasic);
  191. }
  192. fxAILogicBasic.SetAIMonoObj(combatParticleSystemPool);
  193. fxAILogicBasic.Init(startPos, timeLineEventParticleLogicBasic, effectTarget,
  194. targetSpecialDotInfo);
  195. }
  196. #if !COMBAT_SERVER
  197. pool.gameObject.SetActive(true);
  198. #endif
  199. callBack?.Invoke(combatParticleSystemPool);
  200. });
  201. return clock;
  202. }
  203. public Clock CreateParticle(string fxName, Vector3 startPos, ILifetCycleHitPoint fxTarget, bool isRotate,
  204. SpecialDotInfo targetSpecialDotInfo, Action<ParticleSystemPool> callBack)
  205. {
  206. #if !COMBAT_SERVER
  207. Clock clock = ClockPool.GetClock();
  208. CTask<CombatParticleSystemPool> task = GObjectPool.Instance.FetchAsync(fxName + ".prefab",
  209. delegate(CombatParticleSystemPool pool)
  210. {
  211. if (pool == null)
  212. {
  213. callBack?.Invoke(null);
  214. return;
  215. }
  216. if (isRotate && fxTarget != null)
  217. {
  218. SpecialDotInfo specialDotInfo = fxTarget.GetSpecialDotInfo(null);
  219. if (specialDotInfo != null)
  220. {
  221. pool.transform.eulerAngles = specialDotInfo.GetEulerAngles();
  222. }
  223. }
  224. float size = 1;
  225. pool.SetSize(size);
  226. pool.own.transform.position = startPos;
  227. pool.ClearTrail();
  228. callBack?.Invoke(pool);
  229. }, clock);
  230. return clock;
  231. #else
  232. callBack?.Invoke(new CombatParticleSystemPool());
  233. return null;
  234. #endif
  235. }
  236. }