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