GameTimeLineParticleFactory.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 RecycleFix()
  55. {
  56. #if !COMBAT_SERVER
  57. CombatParticleSystemPool[] pools = allCombatParticleSystem.ToArray();
  58. if (pools != null)
  59. {
  60. List<CombatParticleSystemPool> romvePoll = new List<CombatParticleSystemPool>();
  61. romvePoll.AddRange(pools);
  62. for (int i = 0; i < romvePoll.Count; i++)
  63. {
  64. if (pools[i] == null)
  65. {
  66. continue;
  67. }
  68. if (pools[i].gameObject != null)
  69. {
  70. pools[i].gameObject.SetActive(false);
  71. GObjectPool.Instance.Recycle(pools[i]);
  72. }
  73. }
  74. }
  75. #endif
  76. allCombatParticleSystem.Clear();
  77. }
  78. public void RemoveCombatParticleSystemPool(CombatParticleSystemPool combatParticleSystemPool)
  79. {
  80. allCombatParticleSystem.Remove(combatParticleSystemPool);
  81. }
  82. public Clock CreateParticle(TimeLineEventParticleLogicBasic timeLineEventParticleLogicBasic,
  83. ILifetCycleHitPoint effectTarget,
  84. ILifetCycleHitPoint fxTarget, Vector3 startPos, SpecialDotInfo targetSpecialDotInfo,
  85. Action<IGObjectPoolInterface> callBack)
  86. {
  87. Clock clock = CreateParticle(timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.fxName, startPos,
  88. fxTarget,
  89. false, targetSpecialDotInfo, delegate(ParticleSystemPool combatParticleSystemPool)
  90. {
  91. CombatParticleSystemPool pool = combatParticleSystemPool as CombatParticleSystemPool;
  92. if (pool == null)
  93. {
  94. callBack?.Invoke(null);
  95. return;
  96. }
  97. #if !COMBAT_SERVER
  98. pool.InitCombatParticleSystem();
  99. #endif
  100. CombatHeroEntity combatHeroEntity = null;
  101. if (targetSpecialDotInfo != null)
  102. {
  103. combatHeroEntity = targetSpecialDotInfo.heroEntity as CombatHeroEntity;
  104. // if (!timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isActivityCustomTargetPos)
  105. // {
  106. // startPos = targetSpecialDotInfo.GetWorlPos();
  107. // }
  108. if (!timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isNotRotate)
  109. {
  110. pool.transform.eulerAngles = targetSpecialDotInfo.GetEulerAngles();
  111. pool.isNotRotion = false;
  112. }
  113. else
  114. {
  115. pool.isNotRotion = true;
  116. }
  117. // if (heroEntity != null)
  118. // {
  119. // pool.transform.SetParent(heroEntity.CombatHeroTransform.iGObjectPoolInterface.own.transform);
  120. // }
  121. // else
  122. // {
  123. // pool.transform.SetParent(targetSpecialDotInfo.targetTran);
  124. // }
  125. }
  126. if (combatHeroEntity != null && timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isLoop)
  127. {
  128. combatHeroEntity.heroLoopParticle.Add(pool);
  129. pool.HeroEntity = combatHeroEntity;
  130. }
  131. pool.gameObject.SetActive(false);
  132. pool.transform.position = startPos;
  133. if (timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isFollowRootTarget &&
  134. timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.locationType !=
  135. FXLocationType.SceneZero)
  136. {
  137. if (combatHeroEntity != null)
  138. {
  139. pool.transform.SetParent(combatHeroEntity.GetMainHotPoin<CombatHeroHitPoint>()
  140. .GetSpecialDotInfo("").targetTran);
  141. }
  142. pool.transform.localEulerAngles = Vector3.zero;
  143. }
  144. else if (timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isFollowTarget &&
  145. timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.locationType !=
  146. FXLocationType.SceneZero)
  147. {
  148. pool.transform.SetParent(targetSpecialDotInfo.targetTran);
  149. pool.transform.localEulerAngles = Vector3.zero;
  150. pool.transform.localPosition = Vector3.zero;
  151. // pool.targetSpecialDotInfo = targetSpecialDotInfo;
  152. }
  153. else
  154. {
  155. // pool.transform.SetParent(null);
  156. pool.targetSpecialDotInfo = null;
  157. }
  158. FxAILogicBasic fxAILogicBasic = pool.own.GetComponent<FxAILogicBasic>();
  159. if (fxAILogicBasic != null)
  160. {
  161. if (!allFxAiLogicBasic.Contains(fxAILogicBasic))
  162. {
  163. allFxAiLogicBasic.Add(fxAILogicBasic);
  164. }
  165. fxAILogicBasic.SetAIMonoObj(combatParticleSystemPool);
  166. fxAILogicBasic.Init(startPos, timeLineEventParticleLogicBasic, effectTarget,
  167. targetSpecialDotInfo);
  168. }
  169. #if !COMBAT_SERVER
  170. pool.gameObject.SetActive(true);
  171. #endif
  172. callBack?.Invoke(combatParticleSystemPool);
  173. });
  174. return clock;
  175. }
  176. public Clock CreateParticle(string fxName, Vector3 startPos, ILifetCycleHitPoint fxTarget, bool isRotate,
  177. SpecialDotInfo targetSpecialDotInfo, Action<ParticleSystemPool> callBack)
  178. {
  179. #if !COMBAT_SERVER
  180. Clock clock = ClockPool.GetClock();
  181. CTask<CombatParticleSystemPool> task = GObjectPool.Instance.FetchAsync(fxName + ".prefab",
  182. delegate(CombatParticleSystemPool pool)
  183. {
  184. if (pool == null)
  185. {
  186. callBack?.Invoke(null);
  187. return;
  188. }
  189. if (isRotate && fxTarget != null)
  190. {
  191. SpecialDotInfo specialDotInfo = fxTarget.GetSpecialDotInfo(null);
  192. if (specialDotInfo != null)
  193. {
  194. pool.transform.eulerAngles = specialDotInfo.GetEulerAngles();
  195. }
  196. }
  197. float size = 1;
  198. pool.SetSize(size);
  199. pool.own.transform.position = startPos;
  200. callBack?.Invoke(pool);
  201. }, clock);
  202. return clock;
  203. #else
  204. callBack?.Invoke(new CombatParticleSystemPool());
  205. return null;
  206. #endif
  207. }
  208. }