CombatParticleSystemPool.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. own.gameObject.transform.localScale = Vector3.one * size;
  131. return;
  132. }
  133. own.gameObject.transform.localScale =
  134. Vector3.one + Vector3.one * ParticleSystemSize.cardinality * (size - 1) +
  135. Vector3.one * ParticleSystemSize.offValue;
  136. }
  137. protected override void ProActiveObj()
  138. {
  139. activeCount++;
  140. GameObjectDestroyPool.Instance.RomoveDestroyObject(own);
  141. base.ProActiveObj();
  142. }
  143. public override async CTask DelayHide()
  144. {
  145. if (_hideShowEndFx != null)
  146. {
  147. // TimeLineFxParticleTool.Instance.TimeLineFxParticleFactory.CreateParticle(_hideShowEndFx.hideFxName, new Vector3(_pos), null, false,
  148. // null, delegate(CombatParticleSystemPool pool)
  149. // {
  150. // pool.transform.position = gameObject.transform.position;
  151. // pool.transform.eulerAngles = gameObject.transform.eulerAngles;
  152. // if (pool != null)
  153. // {
  154. // pool.SetOder(_lastOder, _lastLayerName);
  155. // }
  156. // });
  157. }
  158. await base.DelayHide();
  159. }
  160. protected override void ProDormancyObj()
  161. {
  162. base.ProDormancyObj();
  163. // RootSortingGroup = null;
  164. }
  165. protected override void ProOnDestroy()
  166. {
  167. base.ProOnDestroy();
  168. }
  169. public int initLogicFrame { get; set; }
  170. public int initRenderFrame { get; set; }
  171. public void UnityRenderUpdate(float deltaTime)
  172. {
  173. if (transform == null)
  174. {
  175. return;
  176. }
  177. _currUpdateTime += deltaTime;
  178. if (_currUpdateTime < UpdateFrequency)
  179. {
  180. return;
  181. }
  182. if (targetSpecialDotInfo != null)
  183. {
  184. transform.position = targetSpecialDotInfo.targetTran.position;
  185. transform.eulerAngles = targetSpecialDotInfo.targetTran.eulerAngles;
  186. }
  187. deltaTime = _currUpdateTime;
  188. _currUpdateTime = 0;
  189. UpdateTime += deltaTime;
  190. float speed = 1;
  191. Play(speed, deltaTime);
  192. }
  193. private void Play(float speed, float deltaTime)
  194. {
  195. if (Particles != null)
  196. {
  197. for (int i = 0; i < Particles.Length; i++)
  198. {
  199. if (Particles[i] == null)
  200. {
  201. continue;
  202. }
  203. ParticleSystem.MainModule mainMode = Particles[i].main;
  204. mainMode.simulationSpeed = speed;
  205. }
  206. }
  207. if (Animators != null)
  208. {
  209. for (int i = 0; i < Animators.Length; i++)
  210. {
  211. if (Animators[i] == null)
  212. {
  213. continue;
  214. }
  215. Animators[i].speed = speed;
  216. }
  217. }
  218. // if (ska != null)
  219. // {
  220. // for (int i = 0; i < ska.Length; i++)
  221. // {
  222. // ska[i].Update(speed * deltaTime.value);
  223. // }
  224. // }
  225. }
  226. public void UnityRenderUpdateFinish()
  227. {
  228. }
  229. public void CombatUpdate(float deltaTime)
  230. {
  231. UnityRenderUpdate(deltaTime);
  232. }
  233. #else
  234. public void CombatUpdate(float time)
  235. {
  236. UpdateTime += time;
  237. }
  238. public int initLogicFrame { get; set; }
  239. public int initRenderFrame { get; set; }
  240. public void UnityRenderUpdate(float time)
  241. {
  242. }
  243. public void UnityRenderUpdateFinish()
  244. {
  245. }
  246. #endif
  247. }
  248. }