GameTimeLineParticleFactory.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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 !COMBAT_SERVER
  93. pool.InitCombatParticleSystem();
  94. #endif
  95. CombatHeroEntity combatHeroEntity = null;
  96. if (targetSpecialDotInfo != null)
  97. {
  98. combatHeroEntity = targetSpecialDotInfo.heroEntity as CombatHeroEntity;
  99. // if (!timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isActivityCustomTargetPos)
  100. // {
  101. // startPos = targetSpecialDotInfo.GetWorlPos();
  102. // }
  103. if (!timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isNotRotate)
  104. {
  105. pool.transform.eulerAngles = targetSpecialDotInfo.GetEulerAngles();
  106. pool.isNotRotion = false;
  107. }
  108. else
  109. {
  110. pool.isNotRotion = true;
  111. }
  112. // if (heroEntity != null)
  113. // {
  114. // pool.transform.SetParent(heroEntity.CombatHeroTransform.iGObjectPoolInterface.own.transform);
  115. // }
  116. // else
  117. // {
  118. // pool.transform.SetParent(targetSpecialDotInfo.targetTran);
  119. // }
  120. }
  121. if (combatHeroEntity != null && timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isLoop)
  122. {
  123. combatHeroEntity.heroLoopParticle.Add(pool);
  124. pool.HeroEntity = combatHeroEntity;
  125. }
  126. pool.gameObject.SetActive(false);
  127. pool.transform.position = startPos;
  128. if (timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isFollowRootTarget &&
  129. timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.locationType !=
  130. FXLocationType.SceneZero)
  131. {
  132. if (combatHeroEntity != null)
  133. {
  134. pool.transform.SetParent(combatHeroEntity.GetMainHotPoin<CombatHeroHitPoint>()
  135. .GetSpecialDotInfo("").targetTran);
  136. }
  137. pool.transform.localEulerAngles = Vector3.zero;
  138. }
  139. else if (timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.isFollowTarget &&
  140. timeLineEventParticleLogicBasic.timeLinePlayFxSerializtion.locationType !=
  141. FXLocationType.SceneZero)
  142. {
  143. pool.transform.localEulerAngles = Vector3.zero;
  144. pool.targetSpecialDotInfo = targetSpecialDotInfo;
  145. }
  146. else
  147. {
  148. // pool.transform.SetParent(null);
  149. pool.targetSpecialDotInfo = null;
  150. }
  151. FxAILogicBasic fxAILogicBasic = pool.own.GetComponent<FxAILogicBasic>();
  152. if (fxAILogicBasic != null)
  153. {
  154. if (!allFxAiLogicBasic.Contains(fxAILogicBasic))
  155. {
  156. allFxAiLogicBasic.Add(fxAILogicBasic);
  157. }
  158. fxAILogicBasic.SetAIMonoObj(combatParticleSystemPool);
  159. fxAILogicBasic.Init(startPos, timeLineEventParticleLogicBasic, effectTarget,
  160. targetSpecialDotInfo);
  161. }
  162. #if !COMBAT_SERVER
  163. pool.gameObject.SetActive(true);
  164. #endif
  165. callBack?.Invoke(combatParticleSystemPool);
  166. });
  167. return clock;
  168. }
  169. public Clock CreateParticle(string fxName, Vector3 startPos, ILifetCycleHitPoint fxTarget, bool isRotate,
  170. SpecialDotInfo targetSpecialDotInfo, Action<ParticleSystemPool> callBack)
  171. {
  172. #if !COMBAT_SERVER
  173. Clock clock = ClockPool.GetClock();
  174. CTask<CombatParticleSystemPool> task = GObjectPool.Instance.FetchAsync(fxName + ".prefab",
  175. delegate(CombatParticleSystemPool pool)
  176. {
  177. if (pool == null)
  178. {
  179. return;
  180. }
  181. // if (!isActive)
  182. // {
  183. // GObjectPool.Instance.RecycleForDestroy(pool);
  184. // return;
  185. // }
  186. if (!allCombatParticleSystem.Contains(pool))
  187. {
  188. allCombatParticleSystem.Add(pool);
  189. }
  190. else
  191. {
  192. LogTool.Error("添加重复");
  193. }
  194. //
  195. // if (targetSpecialDotInfo != null && targetSpecialDotInfo.rootTrnsform != null)
  196. // {
  197. // SortingGroup sortingGroup = targetSpecialDotInfo.rootTrnsform.GetSortingGroup();
  198. // if (sortingGroup != null)
  199. // {
  200. // pool.SetRootSortingGroup(sortingGroup);
  201. // }
  202. // else
  203. // {
  204. // pool.SetOder(0, "Hero");
  205. // }
  206. // }
  207. // else
  208. // {
  209. // pool.SetOder(10000, "Hero");
  210. // }
  211. if (isRotate && fxTarget != null)
  212. {
  213. SpecialDotInfo specialDotInfo = fxTarget.GetSpecialDotInfo(null);
  214. if (specialDotInfo != null)
  215. {
  216. pool.transform.eulerAngles = specialDotInfo.GetEulerAngles();
  217. }
  218. }
  219. float size = 1;
  220. // if (fxTarget != null)
  221. // {
  222. // CombatHeroEntity combatHeroEntity = fxTarget.IfLifeCycle.This<CombatHeroEntity>();
  223. // if (combatHeroEntity != null)
  224. // {
  225. // HeroGameObjectConfig heroGameObjectConfig =
  226. // combatHeroEntity.HeroGameObjectConfig;
  227. // if (heroGameObjectConfig != null)
  228. // {
  229. // size = heroGameObjectConfig.size;
  230. // }
  231. // }
  232. // }
  233. pool.SetSize(size);
  234. pool.own.transform.position = startPos;
  235. callBack?.Invoke(pool);
  236. }, clock);
  237. return clock;
  238. #else
  239. callBack?.Invoke(new CombatParticleSystemPool());
  240. return null;
  241. #endif
  242. }
  243. }