TimeLineEventParticleLogicBasic.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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 = timeLinePlayFxSerializtion.GetRandom(timeLinePlayFxSerializtion.xoff.x,
  185. timeLinePlayFxSerializtion.xoff.y);
  186. float y = timeLinePlayFxSerializtion.GetRandom(timeLinePlayFxSerializtion.yoff.x,
  187. timeLinePlayFxSerializtion.yoff.y);
  188. float z = timeLinePlayFxSerializtion.GetRandom(timeLinePlayFxSerializtion.zoff.x,
  189. timeLinePlayFxSerializtion.zoff.y);
  190. startPos += new Vector3(x, y, z);
  191. targetSpecialDotInfo = null;
  192. }
  193. else if (timeLinePlayFxSerializtion.isActivityCustomTargetPos && customizePos != null &&
  194. customizePos.Length > timeLinePlayFxSerializtion.CustomTargetPosIndex)
  195. {
  196. startPos = customizePos[timeLinePlayFxSerializtion.CustomTargetPosIndex];
  197. targetSpecialDotInfo = null;
  198. }
  199. else if (targetSpecialDotInfo != null &&
  200. timeLinePlayFxSerializtion.locationType != FXLocationType.SceneZero)
  201. {
  202. startPos = targetSpecialDotInfo.GetWorlPos();
  203. }
  204. if (timeLinePlayFxSerializtion.isGround)
  205. {
  206. startPos = new Vector3(startPos.x, (float)0.7f);
  207. }
  208. if (timeLinePlayFxSerializtion.isLoop && timeLinePlayFxSerializtion.loopAlone)
  209. {
  210. if (fxTarget != null)
  211. {
  212. bool isFix = fxTarget.IsLoopFx(timeLinePlayFxSerializtion.fxName);
  213. if (isFix)
  214. {
  215. index++;
  216. ExecuteFxTarget(combatTarget, index);
  217. return;
  218. }
  219. }
  220. }
  221. LoadFx(lifeCycle, fxTarget, startPos, targetSpecialDotInfo);
  222. }
  223. index++;
  224. if (timeLinePlayFxSerializtion.intervalTime > 0)
  225. {
  226. _combatTimer = CombatTimerManager.Instance.AddTimer(
  227. (float)timeLinePlayFxSerializtion.intervalTime * index,
  228. delegate { });
  229. ExecuteFxTarget(combatTarget, index);
  230. }
  231. else
  232. {
  233. ExecuteFxTarget(combatTarget, index);
  234. }
  235. }
  236. protected void ParticleSystemPoolEndFx(ParticleSystemPool particleSystemPool)
  237. {
  238. loopFx.Remove(particleSystemPool);
  239. _allLoadFx.Remove(particleSystemPool);
  240. for (int i = 0; i < _loopTarget.Count; i++)
  241. {
  242. _loopTarget[i].RemoveLoopFx(particleSystemPool);
  243. }
  244. }
  245. protected void LoadFx(ILifetCycleHitPoint effectTarget, ILifetCycleHitPoint fxTarget, Vector3 startPos,
  246. SpecialDotInfo targetSpecialDotInfo)
  247. {
  248. ITimeLineParticleFactory iTimeLineParticleFactory =
  249. TimeLineFxParticleTool.Instance.TimeLineFxParticleFactory;
  250. if (iTimeLineParticleFactory != null)
  251. {
  252. _loadCount++;
  253. Clock clock = iTimeLineParticleFactory.CreateParticle(this, effectTarget, fxTarget, startPos,
  254. targetSpecialDotInfo,
  255. delegate(IGObjectPoolInterface systemPool)
  256. {
  257. _loadCount--;
  258. ParticleSystemPool pool = systemPool as ParticleSystemPool;
  259. if (pool != null)
  260. {
  261. if (IsDis)
  262. {
  263. GObjectPool.Instance.Recycle(pool);
  264. return;
  265. }
  266. pool.fxName = timeLinePlayFxSerializtion.fxName;
  267. pool.OnEndFx = ParticleSystemPoolEndFx;
  268. if (timeLinePlayFxSerializtion.isLoop)
  269. {
  270. loopFx.Add(pool);
  271. if (fxTarget != null)
  272. {
  273. _loopTarget.Add(fxTarget);
  274. fxTarget.AddLoopFx(pool);
  275. }
  276. }
  277. _allLoadFx.Add(pool);
  278. if (timeLinePlayFxSerializtion.isAttSpeed)
  279. {
  280. ITimeLineParticlePlaySpeed timeLineParticlePlaySpeed =
  281. _castEntity as ITimeLineParticlePlaySpeed;
  282. #if !COMBAT_SERVER
  283. pool.palySpeed = timeLineParticlePlaySpeed.GetCurrPlaySpeed(timeLinePlayFxSerializtion);
  284. #endif
  285. }
  286. else
  287. {
  288. #if !COMBAT_SERVER
  289. pool.palySpeed = (float)1;
  290. #endif
  291. }
  292. _timeLineEventLogicGroup.OnInitParticleSystemPoolCallBack?.Invoke(pool);
  293. if (timeLinePlayFxSerializtion.isRoat)
  294. {
  295. pool.own.transform.eulerAngles = customizePos[timeLinePlayFxSerializtion.roatIndex];
  296. }
  297. }
  298. });
  299. if (clock != null)
  300. {
  301. loadTask.Add(clock);
  302. }
  303. }
  304. }
  305. }
  306. }