CombatParticleSystemPool.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. using CombatLibrary.CombatLibrary.CombatCore.CustomizeTimeLogic.FxLogic;
  2. using CombatLibrary.CombatLibrary.CombatCore.Utility;
  3. using Fort23.Core;
  4. using Fort23.UTool;
  5. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
  6. #if !COMBAT_SERVER
  7. using Fort23.Mono;
  8. using GameLogic.Combat.CombatTool;
  9. using UnityEngine;
  10. using UnityEngine.Rendering;
  11. using Utility;
  12. #endif
  13. namespace Fort23.Common
  14. {
  15. /// <summary>
  16. /// 战斗用的,其他地方不要用
  17. /// </summary>
  18. public class CombatParticleSystemPool : ParticleSystemPool
  19. {
  20. public CombatHeroEntity HeroEntity;
  21. public float UpdateTime;
  22. public int guid;
  23. public SpecialDotInfo targetSpecialDotInfo;
  24. public bool isNotRotion;
  25. public int activeCount;
  26. public int remvoeCount;
  27. public float UpdateFrequency = (float)0.031;
  28. private float _currUpdateTime;
  29. public CombatParticleSystemPool()
  30. {
  31. }
  32. #if !COMBAT_SERVER
  33. public void InitCombatParticleSystem()
  34. {
  35. }
  36. public ParticleSystemSize ParticleSystemSize
  37. {
  38. get
  39. {
  40. if (_particleSystemSize == null)
  41. {
  42. _particleSystemSize = own.GetComponent<ParticleSystemSize>();
  43. }
  44. return _particleSystemSize;
  45. }
  46. }
  47. private ParticleSystemSize _particleSystemSize;
  48. public Map<ParticleSystem, int> particleOrder = new Map<ParticleSystem, int>();
  49. public Map<RenderSetting, int> renderSettingOrder = new Map<RenderSetting, int>();
  50. private int _lastOder;
  51. private string _lastLayerName;
  52. // public SortingGroup RootSortingGroup;
  53. // public void SetRootSortingGroup(SortingGroup sortingGroup)
  54. // {
  55. // SetOder(sortingGroup.sortingOrder, sortingGroup.sortingLayerName);
  56. // this.RootSortingGroup = sortingGroup;
  57. // }
  58. public override void DormancyObj()
  59. {
  60. CombatController.currActiveCombat.GameTimeLineParticleFactory.RemoveCombatParticleSystemPool(this);
  61. if (HeroEntity != null)
  62. {
  63. HeroEntity.heroLoopParticle.Remove(this);
  64. }
  65. HeroEntity = null;
  66. base.DormancyObj();
  67. }
  68. public void SetOder(int oder, string layerName)
  69. {
  70. // RootSortingGroup = null;
  71. // if (own != null)
  72. // {
  73. // ShowLayer showLayer = own.GetComponent<ShowLayer>();
  74. // if (showLayer != null)
  75. // {
  76. // if (showLayer.showLayerType == ShowLayer.ShowLayerType.Bottom)
  77. // {
  78. // oder = -3000;
  79. // }
  80. // else if (showLayer.showLayerType == ShowLayer.ShowLayerType.Top)
  81. // {
  82. // oder = 20000;
  83. // }
  84. // }
  85. // }
  86. _lastOder = oder;
  87. _lastLayerName = layerName;
  88. ParticleSystem[] Particles = m_particles;
  89. if (Particles != null)
  90. {
  91. for (int i = 0; i < Particles.Length; i++)
  92. {
  93. Renderer renderer = Particles[i].gameObject.GetComponent<Renderer>();
  94. if (renderer != null)
  95. {
  96. if (particleOrder.ContainsKey(Particles[i]))
  97. {
  98. renderer.sortingOrder = particleOrder[Particles[i]] + oder;
  99. }
  100. else
  101. {
  102. particleOrder.Add(Particles[i], renderer.sortingOrder);
  103. renderer.sortingOrder = renderer.sortingOrder + oder;
  104. }
  105. renderer.sortingLayerName = layerName;
  106. }
  107. }
  108. }
  109. if (RenderSetting != null)
  110. {
  111. for (int i = 0; i < RenderSetting.Length; i++)
  112. {
  113. RenderSetting renderSetting = RenderSetting[i];
  114. if (renderSettingOrder.ContainsKey(renderSetting))
  115. {
  116. renderSetting.SetOrder(renderSettingOrder[renderSetting] + oder, layerName);
  117. }
  118. else
  119. {
  120. renderSettingOrder.Add(renderSetting, renderSetting.order);
  121. renderSetting.SetOrder(renderSetting.order + oder, layerName);
  122. }
  123. }
  124. }
  125. }
  126. public void SetSize(float size)
  127. {
  128. if (ParticleSystemSize == null)
  129. {
  130. return;
  131. }
  132. own.gameObject.transform.localScale =
  133. Vector3.one + Vector3.one * ParticleSystemSize.cardinality * (size - 1) +
  134. Vector3.one * ParticleSystemSize.offValue;
  135. }
  136. protected override void ProActiveObj()
  137. {
  138. activeCount++;
  139. GameObjectDestroyPool.Instance.RomoveDestroyObject(own);
  140. base.ProActiveObj();
  141. }
  142. public override async CTask DelayHide()
  143. {
  144. if (_hideShowEndFx != null)
  145. {
  146. // TimeLineFxParticleTool.Instance.TimeLineFxParticleFactory.CreateParticle(_hideShowEndFx.hideFxName, new Vector3(_pos), null, false,
  147. // null, delegate(CombatParticleSystemPool pool)
  148. // {
  149. // pool.transform.position = gameObject.transform.position;
  150. // pool.transform.eulerAngles = gameObject.transform.eulerAngles;
  151. // if (pool != null)
  152. // {
  153. // pool.SetOder(_lastOder, _lastLayerName);
  154. // }
  155. // });
  156. }
  157. await base.DelayHide();
  158. }
  159. protected override void ProDormancyObj()
  160. {
  161. base.ProDormancyObj();
  162. // RootSortingGroup = null;
  163. }
  164. protected override void ProOnDestroy()
  165. {
  166. base.ProOnDestroy();
  167. }
  168. public int initLogicFrame { get; set; }
  169. public int initRenderFrame { get; set; }
  170. public void UnityRenderUpdate(float deltaTime)
  171. {
  172. if (transform == null)
  173. {
  174. return;
  175. }
  176. _currUpdateTime += deltaTime;
  177. if (_currUpdateTime < UpdateFrequency)
  178. {
  179. return;
  180. }
  181. if (targetSpecialDotInfo != null)
  182. {
  183. transform.position = targetSpecialDotInfo.targetTran.position;
  184. transform.eulerAngles = targetSpecialDotInfo.targetTran.eulerAngles;
  185. }
  186. deltaTime = _currUpdateTime;
  187. _currUpdateTime = 0;
  188. UpdateTime += deltaTime;
  189. float speed = 1;
  190. Play(speed, deltaTime);
  191. }
  192. private void Play(float speed, float deltaTime)
  193. {
  194. if (Particles != null)
  195. {
  196. for (int i = 0; i < Particles.Length; i++)
  197. {
  198. if (Particles[i] == null)
  199. {
  200. continue;
  201. }
  202. ParticleSystem.MainModule mainMode = Particles[i].main;
  203. mainMode.simulationSpeed = speed;
  204. }
  205. }
  206. if (Animators != null)
  207. {
  208. for (int i = 0; i < Animators.Length; i++)
  209. {
  210. if (Animators[i] == null)
  211. {
  212. continue;
  213. }
  214. Animators[i].speed = speed;
  215. }
  216. }
  217. // if (ska != null)
  218. // {
  219. // for (int i = 0; i < ska.Length; i++)
  220. // {
  221. // ska[i].Update(speed * deltaTime.value);
  222. // }
  223. // }
  224. }
  225. public void UnityRenderUpdateFinish()
  226. {
  227. }
  228. public void CombatUpdate(float deltaTime)
  229. {
  230. UnityRenderUpdate(deltaTime);
  231. }
  232. #else
  233. public void CombatUpdate(float time)
  234. {
  235. UpdateTime += time;
  236. }
  237. public int initLogicFrame { get; set; }
  238. public int initRenderFrame { get; set; }
  239. public void UnityRenderUpdate(float time)
  240. {
  241. }
  242. public void UnityRenderUpdateFinish()
  243. {
  244. }
  245. #endif
  246. }
  247. }