CombatParticleSystemPool.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. 
  2. using CombatLibrary.CombatLibrary.CombatCore.CustomizeTimeLogic.FxLogic;
  3. using CombatLibrary.CombatLibrary.CombatCore.Utility;
  4. using Fort23.Core;
  5. using Fort23.UTool;
  6. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
  7. #if !COMBAT_SERVER
  8. using Fort23.Mono;
  9. using GameLogic.Combat.CombatTool;
  10. using UnityEngine;
  11. using UnityEngine.Rendering;
  12. using Utility;
  13. #endif
  14. namespace Fort23.Common
  15. {
  16. /// <summary>
  17. /// 战斗用的,其他地方不要用
  18. /// </summary>
  19. public class CombatParticleSystemPool : ParticleSystemPool
  20. {
  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. base.DormancyObj();
  62. }
  63. public void SetOder(int oder, string layerName)
  64. {
  65. RootSortingGroup = null;
  66. // if (own != null)
  67. // {
  68. // ShowLayer showLayer = own.GetComponent<ShowLayer>();
  69. // if (showLayer != null)
  70. // {
  71. // if (showLayer.showLayerType == ShowLayer.ShowLayerType.Bottom)
  72. // {
  73. // oder = -3000;
  74. // }
  75. // else if (showLayer.showLayerType == ShowLayer.ShowLayerType.Top)
  76. // {
  77. // oder = 20000;
  78. // }
  79. // }
  80. // }
  81. _lastOder = oder;
  82. _lastLayerName = layerName;
  83. ParticleSystem[] Particles = m_particles;
  84. if (Particles != null)
  85. {
  86. for (int i = 0; i < Particles.Length; i++)
  87. {
  88. Renderer renderer = Particles[i].gameObject.GetComponent<Renderer>();
  89. if (renderer != null)
  90. {
  91. if (particleOrder.ContainsKey(Particles[i]))
  92. {
  93. renderer.sortingOrder = particleOrder[Particles[i]] + oder;
  94. }
  95. else
  96. {
  97. particleOrder.Add(Particles[i], renderer.sortingOrder);
  98. renderer.sortingOrder = renderer.sortingOrder + oder;
  99. }
  100. renderer.sortingLayerName = layerName;
  101. }
  102. }
  103. }
  104. if (RenderSetting != null)
  105. {
  106. for (int i = 0; i < RenderSetting.Length; i++)
  107. {
  108. RenderSetting renderSetting = RenderSetting[i];
  109. if (renderSettingOrder.ContainsKey(renderSetting))
  110. {
  111. renderSetting.SetOrder(renderSettingOrder[renderSetting] + oder, layerName);
  112. }
  113. else
  114. {
  115. renderSettingOrder.Add(renderSetting, renderSetting.order);
  116. renderSetting.SetOrder(renderSetting.order + oder, layerName);
  117. }
  118. }
  119. }
  120. }
  121. public void SetSize(float size)
  122. {
  123. if (ParticleSystemSize == null)
  124. {
  125. return;
  126. }
  127. own.gameObject.transform.localScale =
  128. Vector3.one + Vector3.one * ParticleSystemSize.cardinality * (size - 1) +
  129. Vector3.one * ParticleSystemSize.offValue;
  130. }
  131. protected override void ProActiveObj()
  132. {
  133. activeCount++;
  134. GameObjectDestroyPool.Instance.RomoveDestroyObject(own);
  135. base.ProActiveObj();
  136. }
  137. public override async CTask DelayHide()
  138. {
  139. if (_hideShowEndFx != null)
  140. {
  141. // TimeLineFxParticleTool.Instance.TimeLineFxParticleFactory.CreateParticle(_hideShowEndFx.hideFxName, new Vector3(_pos), null, false,
  142. // null, delegate(CombatParticleSystemPool pool)
  143. // {
  144. // pool.transform.position = gameObject.transform.position;
  145. // pool.transform.eulerAngles = gameObject.transform.eulerAngles;
  146. // if (pool != null)
  147. // {
  148. // pool.SetOder(_lastOder, _lastLayerName);
  149. // }
  150. // });
  151. }
  152. await base.DelayHide();
  153. }
  154. protected override void ProDormancyObj()
  155. {
  156. base.ProDormancyObj();
  157. RootSortingGroup = null;
  158. }
  159. protected override void ProOnDestroy()
  160. {
  161. base.ProOnDestroy();
  162. }
  163. public int initLogicFrame { get; set; }
  164. public int initRenderFrame { get; set; }
  165. public void UnityRenderUpdate(float deltaTime)
  166. {
  167. if (transform == null)
  168. {
  169. return;
  170. }
  171. _currUpdateTime += deltaTime;
  172. if (_currUpdateTime < UpdateFrequency)
  173. {
  174. return;
  175. }
  176. deltaTime = _currUpdateTime;
  177. _currUpdateTime = 0;
  178. if (RootSortingGroup != null)
  179. {
  180. if (!RootSortingGroup.sortingLayerName.Equals(_lastLayerName) ||
  181. RootSortingGroup.sortingOrder != _lastOder)
  182. {
  183. SortingGroup sortingGroup = RootSortingGroup;
  184. SetOder(sortingGroup.sortingOrder, sortingGroup.sortingLayerName);
  185. RootSortingGroup = sortingGroup;
  186. }
  187. }
  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. }