GameTimeLineParticleFactory.cs 9.6 KB

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