TimeLineEventParticleLogicBasic.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Common.Utility.CombatTimer;
  4. using Fort23.Core;
  5. #if !COMBAT_SERVER
  6. using Fort23.Core;
  7. #endif
  8. using Fort23.UTool;
  9. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
  10. #if !COMBAT_SERVER
  11. using UnityEngine;
  12. #endif
  13. namespace UTool.CustomizeTimeLogic.FxLogic.TimeLineEventLogic
  14. {
  15. public class TimeLineEventParticleLogicBasic : TimeLineEventLogicBasic
  16. {
  17. // private Timer timer;
  18. private BetterList<Clock> loadTask = new BetterList<Clock>();
  19. // private BetterList<string> long = new BetterList<Clock>();
  20. public BetterList<ParticleSystemPool> loopFx = new BetterList<ParticleSystemPool>();
  21. public BetterList<ParticleSystemPool> _allLoadFx = new BetterList<ParticleSystemPool>();
  22. public BetterList<ILifetCycleHitPoint> _loopTarget = new BetterList<ILifetCycleHitPoint>();
  23. private CombatTimer _combatTimer;
  24. private int _loadCount;
  25. public TimeLinePlayFxSerializtion timeLinePlayFxSerializtion
  26. {
  27. get { return mTimeLineAssetSerialization as TimeLinePlayFxSerializtion; }
  28. }
  29. protected override void ProDormancyObj()
  30. {
  31. loopFx.Clear();
  32. _allLoadFx.Clear();
  33. _loopTarget.Clear();
  34. loadTask.Clear();
  35. CombatTimerManager.Instance.RemoveTimer(_combatTimer);
  36. _combatTimer = null;
  37. }
  38. protected override void ProSetCombatInfo()
  39. {
  40. }
  41. protected override void ProEnter()
  42. {
  43. // ITimeLineTriggerEvent trigger = _targetEntity as ITimeLineTriggerEvent;
  44. // if (trigger != null)
  45. {
  46. BetterList<ILifetCycleHitPoint> timeLineEntities = GetSkillTarget();
  47. ExecuteFxTarget(timeLineEntities, 0);
  48. }
  49. }
  50. protected override void ProLeave()
  51. {
  52. }
  53. protected override void ProTimeUpdate()
  54. {
  55. }
  56. protected override void ProBreakTimeLine()
  57. {
  58. for (int i = 0; i < loadTask.Count; i++)
  59. {
  60. loadTask[i].Dispose();
  61. }
  62. CombatTimerManager.Instance.RemoveTimer(_combatTimer);
  63. _combatTimer = null;
  64. CloseLoopFx();
  65. loadTask.Clear();
  66. }
  67. public override bool IsFinish()
  68. {
  69. return _allLoadFx.Count <= 0 && _loadCount <= 0;
  70. }
  71. public void CloseLoopFx()
  72. {
  73. if (loopFx.Count <= 0)
  74. {
  75. return;
  76. }
  77. ParticleSystemPool[] pool = loopFx.ToArray();
  78. for (int i = 0; i < pool.Length; i++)
  79. {
  80. for (int j = 0; j < _loopTarget.Count; j++)
  81. {
  82. _loopTarget[j].RemoveLoopFx(pool[i]);
  83. }
  84. GObjectPool.Instance.Recycle(pool[i]);
  85. }
  86. _loopTarget.Clear();
  87. loopFx.Clear();
  88. }
  89. public void CloseAllFx()
  90. {
  91. if (_allLoadFx.Count <= 0)
  92. {
  93. return;
  94. }
  95. ParticleSystemPool[] pool = _allLoadFx.ToArray();
  96. for (int i = 0; i < pool.Length; i++)
  97. {
  98. GObjectPool.Instance.Recycle(pool[i]);
  99. }
  100. _allLoadFx.Clear();
  101. }
  102. protected override void ProDispose()
  103. {
  104. for (int i = 0; i < loadTask.Count; i++)
  105. {
  106. loadTask[i].Dispose();
  107. }
  108. CombatTimerManager.Instance.RemoveTimer(_combatTimer);
  109. _combatTimer = null;
  110. loadTask.Clear();
  111. if (currTarget != null)
  112. {
  113. currTarget.Dispose();
  114. }
  115. currTarget = null;
  116. CloseAllFx();
  117. loopFx.Clear();
  118. _allLoadFx.Clear();
  119. _loopTarget.Clear();
  120. }
  121. private void ExecuteFxTarget(BetterList<ILifetCycleHitPoint> combatTarget, int index)
  122. {
  123. if (combatTarget.Count <= index)
  124. {
  125. return;
  126. }
  127. ILifetCycleHitPoint lifeCycle = combatTarget[index];
  128. if (lifeCycle == null)
  129. {
  130. // LogTool.Log("一个空的目标");
  131. index++;
  132. ExecuteFxTarget(combatTarget, index);
  133. return;
  134. }
  135. if (!string.IsNullOrEmpty(timeLinePlayFxSerializtion.fxName))
  136. {
  137. ILifetCycleHitPoint fxTarget = null;
  138. Vector3 startPos = Vector3.one;
  139. SpecialDotInfo targetSpecialDotInfo = null;
  140. switch (timeLinePlayFxSerializtion.locationType)
  141. {
  142. case FXLocationType.Oneself:
  143. fxTarget = _castEntity.GetMainHotPoin<ILifetCycleHitPoint>(true);
  144. break;
  145. case FXLocationType.Target:
  146. fxTarget = lifeCycle;
  147. break;
  148. case FXLocationType.CustomTarget:
  149. fxTarget = lifeCycle;
  150. break;
  151. case FXLocationType.SceneZero:
  152. fxTarget = _castEntity.GetMainHotPoin<ILifetCycleHitPoint>(false);
  153. startPos = TimeLineEventLogicGroup.SceneWorldPos();
  154. break;
  155. case FXLocationType.OneselfSpecialDot:
  156. fxTarget = _castEntity.GetMainHotPoin<ILifetCycleHitPoint>(false);
  157. break;
  158. case FXLocationType.TargetSpecialDot:
  159. fxTarget = lifeCycle;
  160. break;
  161. }
  162. if (fxTarget != null)
  163. {
  164. if (!string.IsNullOrEmpty(timeLinePlayFxSerializtion.hitPointGroupName))
  165. {
  166. ILifetCycleHitPoint newHitPoint =
  167. fxTarget.IfLifeCycle.GetILifetCycleHitPoint<ILifetCycleHitPoint>(
  168. timeLinePlayFxSerializtion.hitPointGroupName, true, true);
  169. targetSpecialDotInfo =
  170. newHitPoint.GetSpecialDotInfo(timeLinePlayFxSerializtion.targetSpecialDotName);
  171. }
  172. else
  173. {
  174. targetSpecialDotInfo =
  175. fxTarget.GetSpecialDotInfo(timeLinePlayFxSerializtion.targetSpecialDotName);
  176. }
  177. }
  178. if (timeLinePlayFxSerializtion.isUseRandom)
  179. {
  180. if (targetSpecialDotInfo != null)
  181. {
  182. startPos = targetSpecialDotInfo.GetWorlPos();
  183. }
  184. float x = Random.Range(timeLinePlayFxSerializtion.xoff.x, timeLinePlayFxSerializtion.xoff.y);
  185. float y = Random.Range(timeLinePlayFxSerializtion.yoff.x, timeLinePlayFxSerializtion.yoff.y);
  186. float z = Random.Range(timeLinePlayFxSerializtion.zoff.x, timeLinePlayFxSerializtion.zoff.y);
  187. startPos += new Vector3(x, y, z);
  188. targetSpecialDotInfo = null;
  189. }
  190. else if (timeLinePlayFxSerializtion.isActivityCustomTargetPos && customizePos != null &&
  191. customizePos.Length > timeLinePlayFxSerializtion.CustomTargetPosIndex)
  192. {
  193. startPos = customizePos[timeLinePlayFxSerializtion.CustomTargetPosIndex];
  194. targetSpecialDotInfo = null;
  195. }
  196. else if (targetSpecialDotInfo != null &&
  197. timeLinePlayFxSerializtion.locationType != FXLocationType.SceneZero)
  198. {
  199. startPos = targetSpecialDotInfo.GetWorlPos();
  200. }
  201. if (timeLinePlayFxSerializtion.isGround)
  202. {
  203. startPos = new Vector3(startPos.x, (float)0.7f);
  204. }
  205. if (timeLinePlayFxSerializtion.isLoop && timeLinePlayFxSerializtion.loopAlone)
  206. {
  207. if (fxTarget != null)
  208. {
  209. bool isFix = fxTarget.IsLoopFx(timeLinePlayFxSerializtion.fxName);
  210. if (isFix)
  211. {
  212. index++;
  213. ExecuteFxTarget(combatTarget, index);
  214. return;
  215. }
  216. }
  217. }
  218. LoadFx(lifeCycle, fxTarget, startPos, targetSpecialDotInfo);
  219. }
  220. index++;
  221. if (timeLinePlayFxSerializtion.intervalTime > 0)
  222. {
  223. _combatTimer = CombatTimerManager.Instance.AddTimer(
  224. (float)timeLinePlayFxSerializtion.intervalTime * index,
  225. delegate { });
  226. ExecuteFxTarget(combatTarget, index);
  227. }
  228. else
  229. {
  230. ExecuteFxTarget(combatTarget, index);
  231. }
  232. }
  233. protected void ParticleSystemPoolEndFx(ParticleSystemPool particleSystemPool)
  234. {
  235. loopFx.Remove(particleSystemPool);
  236. _allLoadFx.Remove(particleSystemPool);
  237. for (int i = 0; i < _loopTarget.Count; i++)
  238. {
  239. _loopTarget[i].RemoveLoopFx(particleSystemPool);
  240. }
  241. }
  242. protected void LoadFx(ILifetCycleHitPoint effectTarget, ILifetCycleHitPoint fxTarget, Vector3 startPos,
  243. SpecialDotInfo targetSpecialDotInfo)
  244. {
  245. ITimeLineParticleFactory iTimeLineParticleFactory =
  246. TimeLineFxParticleTool.Instance.TimeLineFxParticleFactory;
  247. if (iTimeLineParticleFactory != null)
  248. {
  249. _loadCount++;
  250. Clock clock = iTimeLineParticleFactory.CreateParticle(this, effectTarget, fxTarget, startPos,
  251. targetSpecialDotInfo,
  252. delegate(IGObjectPoolInterface systemPool)
  253. {
  254. _loadCount--;
  255. ParticleSystemPool pool = systemPool as ParticleSystemPool;
  256. if (pool != null)
  257. {
  258. if (IsDis)
  259. {
  260. GObjectPool.Instance.Recycle(pool);
  261. return;
  262. }
  263. pool.fxName = timeLinePlayFxSerializtion.fxName;
  264. pool.OnEndFx = ParticleSystemPoolEndFx;
  265. if (timeLinePlayFxSerializtion.isLoop)
  266. {
  267. loopFx.Add(pool);
  268. if (fxTarget != null)
  269. {
  270. _loopTarget.Add(fxTarget);
  271. fxTarget.AddLoopFx(pool);
  272. }
  273. }
  274. _allLoadFx.Add(pool);
  275. if (timeLinePlayFxSerializtion.isAttSpeed)
  276. {
  277. ITimeLineParticlePlaySpeed timeLineParticlePlaySpeed =
  278. _castEntity as ITimeLineParticlePlaySpeed;
  279. #if !COMBAT_SERVER
  280. pool.palySpeed = timeLineParticlePlaySpeed.GetCurrPlaySpeed(timeLinePlayFxSerializtion);
  281. #endif
  282. }
  283. else
  284. {
  285. #if !COMBAT_SERVER
  286. pool.palySpeed = (float)1;
  287. #endif
  288. }
  289. _timeLineEventLogicGroup.OnInitParticleSystemPoolCallBack?.Invoke(pool);
  290. if (timeLinePlayFxSerializtion.isRoat)
  291. {
  292. pool.own.transform.eulerAngles = customizePos[timeLinePlayFxSerializtion.roatIndex];
  293. }
  294. }
  295. });
  296. if (clock != null)
  297. {
  298. loadTask.Add(clock);
  299. }
  300. }
  301. }
  302. }
  303. }