CombatParticleSystemPool.cs 8.9 KB

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