GameTimeLineParticleFactory.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 UnityEngine;
  10. using UnityEngine.Rendering;
  11. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
  12. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventLogic;
  13. public class GameTimeLineParticleFactory : ITimeLineParticleFactory
  14. {
  15. protected List<CombatParticleSystemPool> allCombatParticleSystem =
  16. new List<CombatParticleSystemPool>();
  17. protected List<FxAILogicBasic> allFxAiLogicBasic = new List<FxAILogicBasic>();
  18. protected bool _isUpdateState;
  19. private List<FxAILogicBasic> _removeFxAiLogicBasic = new List<FxAILogicBasic>();
  20. public void RemoveFxAILogicBasic(FxAILogicBasic fxAILogicBasic)
  21. {
  22. if (_isUpdateState)
  23. {
  24. _removeFxAiLogicBasic.Add(fxAILogicBasic);
  25. }
  26. else
  27. {
  28. allFxAiLogicBasic.Remove(fxAILogicBasic);
  29. }
  30. }
  31. public void CombatUpdate(float time)
  32. {
  33. _isUpdateState = true;
  34. for (int i = 0; i < allFxAiLogicBasic.Count; i++)
  35. {
  36. allFxAiLogicBasic[i].CombatUpdate(time);
  37. }
  38. _isUpdateState = false;
  39. for (int i = 0; i < _removeFxAiLogicBasic.Count; i++)
  40. {
  41. allFxAiLogicBasic.Remove(_removeFxAiLogicBasic[i]);
  42. }
  43. _removeFxAiLogicBasic.Clear();
  44. for (int i = 0; i < allCombatParticleSystem.Count; i++)
  45. {
  46. allCombatParticleSystem[i].CombatUpdate(time);
  47. }
  48. }
  49. public void Dispose()
  50. {
  51. allFxAiLogicBasic.Clear();
  52. }
  53. public void RecycleFix()
  54. {
  55. #if !COMBAT_SERVER
  56. CombatParticleSystemPool[] pools = allCombatParticleSystem.ToArray();
  57. if (pools != null)
  58. {
  59. List<CombatParticleSystemPool> romvePoll = new List<CombatParticleSystemPool>();
  60. romvePoll.AddRange(pools);
  61. for (int i = 0; i < romvePoll.Count; i++)
  62. {
  63. if (pools[i] == null)
  64. {
  65. continue;
  66. }
  67. if (pools[i].gameObject != null)
  68. {
  69. pools[i].gameObject.SetActive(false);
  70. GObjectPool.Instance.Recycle(pools[i]);
  71. }
  72. }
  73. }
  74. #endif
  75. allCombatParticleSystem.Clear();
  76. }
  77. public void RemoveCombatParticleSystemPool(CombatParticleSystemPool combatParticleSystemPool)
  78. {
  79. allCombatParticleSystem.Remove(combatParticleSystemPool);
  80. }
  81. public Clock CreateParticle(TimeLineEventParticleLogicBasic timeLineEventParticleLogicBasic,
  82. ILifetCycleHitPoint effectTarget,
  83. ILifetCycleHitPoint fxTarget, Vector3 startPos, SpecialDotInfo targetSpecialDotInfo,
  84. Action<IGObjectPoolInterface> callBack)
  85. {
  86. Clock clock = CreateParticle(timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.fxName, startPos,
  87. fxTarget,
  88. false, targetSpecialDotInfo, delegate(ParticleSystemPool combatParticleSystemPool)
  89. {
  90. CombatParticleSystemPool pool = combatParticleSystemPool as CombatParticleSystemPool;
  91. #if !COMBAT_SERVER
  92. pool.InitCombatParticleSystem();
  93. #endif
  94. if (targetSpecialDotInfo != null)
  95. {
  96. #if !COMBAT_SERVER
  97. // CombatHeroEntity heroEntity = targetSpecialDotInfo.heroEntity as CombatHeroEntity;
  98. // if (heroEntity.CombatHeroTransform.iGObjectPoolInterface == null)
  99. // {
  100. // return;
  101. // }
  102. #endif
  103. // if (!timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isActivityCustomTargetPos)
  104. // {
  105. // startPos = targetSpecialDotInfo.GetWorlPos();
  106. // }
  107. #if !COMBAT_SERVER
  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. #endif
  126. }
  127. else
  128. {
  129. }
  130. #if !COMBAT_SERVER
  131. pool.gameObject.SetActive(false);
  132. pool.transform.position = startPos;
  133. if (timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isFollowTarget &&
  134. timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.locationType !=
  135. FXLocationType.SceneZero)
  136. {
  137. pool.transform.localEulerAngles = Vector3.zero;
  138. pool.targetSpecialDotInfo = targetSpecialDotInfo;
  139. }
  140. else
  141. {
  142. // pool.transform.SetParent(null);
  143. pool.targetSpecialDotInfo = null;
  144. }
  145. #endif
  146. FxAILogicBasic fxAILogicBasic = pool.own.GetComponent<FxAILogicBasic>();
  147. if (fxAILogicBasic != null)
  148. {
  149. if (!allFxAiLogicBasic.Contains(fxAILogicBasic))
  150. {
  151. allFxAiLogicBasic.Add(fxAILogicBasic);
  152. }
  153. fxAILogicBasic.SetAIMonoObj(combatParticleSystemPool);
  154. fxAILogicBasic.Init(startPos, timeLineEventParticleLogicBasic, effectTarget,
  155. targetSpecialDotInfo);
  156. }
  157. #if !COMBAT_SERVER
  158. pool.gameObject.SetActive(true);
  159. #endif
  160. callBack?.Invoke(combatParticleSystemPool);
  161. });
  162. return clock;
  163. }
  164. public Clock CreateParticle(string fxName, Vector3 startPos, ILifetCycleHitPoint fxTarget, bool isRotate,
  165. SpecialDotInfo targetSpecialDotInfo, Action<ParticleSystemPool> callBack)
  166. {
  167. #if !COMBAT_SERVER
  168. Clock clock = ClockPool.GetClock();
  169. CTask<CombatParticleSystemPool> task = GObjectPool.Instance.FetchAsync(fxName + ".prefab",
  170. delegate(CombatParticleSystemPool pool)
  171. {
  172. if (pool == null)
  173. {
  174. return;
  175. }
  176. // if (!isActive)
  177. // {
  178. // GObjectPool.Instance.RecycleForDestroy(pool);
  179. // return;
  180. // }
  181. if (!allCombatParticleSystem.Contains(pool))
  182. {
  183. allCombatParticleSystem.Add(pool);
  184. }
  185. else
  186. {
  187. LogTool.Error("添加重复");
  188. }
  189. //
  190. // if (targetSpecialDotInfo != null && targetSpecialDotInfo.rootTrnsform != null)
  191. // {
  192. // SortingGroup sortingGroup = targetSpecialDotInfo.rootTrnsform.GetSortingGroup();
  193. // if (sortingGroup != null)
  194. // {
  195. // pool.SetRootSortingGroup(sortingGroup);
  196. // }
  197. // else
  198. // {
  199. // pool.SetOder(0, "Hero");
  200. // }
  201. // }
  202. // else
  203. // {
  204. // pool.SetOder(10000, "Hero");
  205. // }
  206. if (isRotate && fxTarget != null)
  207. {
  208. SpecialDotInfo specialDotInfo = fxTarget.GetSpecialDotInfo(null);
  209. if (specialDotInfo != null)
  210. {
  211. pool.transform.eulerAngles = specialDotInfo.GetEulerAngles();
  212. }
  213. }
  214. float size = 1;
  215. // if (fxTarget != null)
  216. // {
  217. // CombatHeroEntity combatHeroEntity = fxTarget.IfLifeCycle.This<CombatHeroEntity>();
  218. // if (combatHeroEntity != null)
  219. // {
  220. // HeroGameObjectConfig heroGameObjectConfig =
  221. // combatHeroEntity.HeroGameObjectConfig;
  222. // if (heroGameObjectConfig != null)
  223. // {
  224. // size = heroGameObjectConfig.size;
  225. // }
  226. // }
  227. // }
  228. pool.SetSize(size);
  229. pool.own.transform.position = startPos;
  230. callBack?.Invoke(pool);
  231. }, clock);
  232. return clock;
  233. #else
  234. callBack?.Invoke(new CombatParticleSystemPool());
  235. return null;
  236. #endif
  237. }
  238. }