ParticleSystems.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. 
  2. // =================================
  3. // Namespaces.
  4. // =================================
  5. using UnityEngine;
  6. // =================================
  7. // Define namespace.
  8. // =================================
  9. namespace MirzaBeig
  10. {
  11. namespace ParticleSystems
  12. {
  13. // =================================
  14. // Classes.
  15. // =================================
  16. public class ParticleSystems : MonoBehaviour
  17. {
  18. // =================================
  19. // Nested classes and structures.
  20. // =================================
  21. // =================================
  22. // Variables.
  23. // =================================
  24. public ParticleSystem[] particleSystems { get; set; }
  25. // Event delegates.
  26. public delegate void onParticleSystemsDeadEventHandler();
  27. public event onParticleSystemsDeadEventHandler onParticleSystemsDeadEvent;
  28. // =================================
  29. // Functions.
  30. // =================================
  31. // ...
  32. protected virtual void Awake()
  33. {
  34. particleSystems = GetComponentsInChildren<ParticleSystem>();
  35. }
  36. // ...
  37. protected virtual void Start()
  38. {
  39. }
  40. // ...
  41. protected virtual void Update()
  42. {
  43. }
  44. // ...
  45. protected virtual void LateUpdate()
  46. {
  47. if (onParticleSystemsDeadEvent != null)
  48. {
  49. if (!isAlive())
  50. {
  51. onParticleSystemsDeadEvent();
  52. }
  53. }
  54. }
  55. // ...
  56. public void reset()
  57. {
  58. //simulate(0.0f, true);
  59. for (int i = 0; i < particleSystems.Length; i++)
  60. {
  61. particleSystems[i].time = 0.0f;
  62. }
  63. }
  64. // ...
  65. public void play()
  66. {
  67. for (int i = 0; i < particleSystems.Length; i++)
  68. {
  69. particleSystems[i].Play(false);
  70. }
  71. }
  72. // ...
  73. public void pause()
  74. {
  75. for (int i = 0; i < particleSystems.Length; i++)
  76. {
  77. particleSystems[i].Pause(false);
  78. }
  79. }
  80. // ...
  81. public void stop()
  82. {
  83. for (int i = 0; i < particleSystems.Length; i++)
  84. {
  85. particleSystems[i].Stop(false);
  86. }
  87. }
  88. // ...
  89. public void clear()
  90. {
  91. for (int i = 0; i < particleSystems.Length; i++)
  92. {
  93. particleSystems[i].Clear(false);
  94. }
  95. }
  96. // ...
  97. public void setLoop(bool loop)
  98. {
  99. for (int i = 0; i < particleSystems.Length; i++)
  100. {
  101. ParticleSystem.MainModule m = particleSystems[i].main;
  102. m.loop = loop;
  103. }
  104. }
  105. // ...
  106. public void setPlaybackSpeed(float speed)
  107. {
  108. for (int i = 0; i < particleSystems.Length; i++)
  109. {
  110. ParticleSystem.MainModule m = particleSystems[i].main;
  111. m.simulationSpeed = speed;
  112. }
  113. }
  114. // ...
  115. public void simulate(float time, bool reset = false)
  116. {
  117. for (int i = 0; i < particleSystems.Length; i++)
  118. {
  119. particleSystems[i].Simulate(time, false, reset);
  120. }
  121. }
  122. // ...
  123. public bool isAlive()
  124. {
  125. for (int i = 0; i < particleSystems.Length; i++)
  126. {
  127. if (particleSystems[i])
  128. {
  129. if (particleSystems[i].IsAlive())
  130. {
  131. return true;
  132. }
  133. }
  134. }
  135. return false;
  136. }
  137. // ...
  138. public bool isPlaying(bool checkAll = false)
  139. {
  140. if (particleSystems.Length == 0)
  141. {
  142. return false;
  143. }
  144. else if (!checkAll)
  145. {
  146. return particleSystems[0].isPlaying;
  147. }
  148. else
  149. {
  150. for (int i = 0; i < 0; i++)
  151. {
  152. if (!particleSystems[i].isPlaying)
  153. {
  154. return false;
  155. }
  156. }
  157. return true;
  158. }
  159. }
  160. // ...
  161. public int getParticleCount()
  162. {
  163. int pcount = 0;
  164. for (int i = 0; i < particleSystems.Length; i++)
  165. {
  166. if (particleSystems[i])
  167. {
  168. pcount += particleSystems[i].particleCount;
  169. }
  170. }
  171. return pcount;
  172. }
  173. // =================================
  174. // End functions.
  175. // =================================
  176. }
  177. // =================================
  178. // End namespace.
  179. // =================================
  180. }
  181. }
  182. // =================================
  183. // --END-- //
  184. // =================================