DetonatorBurstEmitter.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. using System;
  2. using UnityEngine;
  3. public class DetonatorBurstEmitter : DetonatorComponent
  4. {
  5. public override void Init()
  6. {
  7. MonoBehaviour.print("UNUSED");
  8. }
  9. public void Awake()
  10. {
  11. this._particleEmitter = base.gameObject.AddComponent<EllipsoidParticleEmitter>();
  12. this._particleRenderer = base.gameObject.AddComponent<ParticleRenderer>();
  13. this._particleAnimator = base.gameObject.AddComponent<ParticleAnimator>();
  14. this._particleEmitter.hideFlags = HideFlags.HideAndDontSave;
  15. this._particleRenderer.hideFlags = HideFlags.HideAndDontSave;
  16. this._particleAnimator.hideFlags = HideFlags.HideAndDontSave;
  17. this._particleAnimator.damping = this._baseDamping;
  18. this._particleEmitter.emit = false;
  19. this._particleRenderer.maxParticleSize = this.maxScreenSize;
  20. this._particleRenderer.material = this.material;
  21. this._particleRenderer.material.color = Color.white;
  22. this._particleAnimator.sizeGrow = this.sizeGrow;
  23. if (this.explodeOnAwake)
  24. {
  25. this.Explode();
  26. }
  27. }
  28. private void Update()
  29. {
  30. if (this.exponentialGrowth)
  31. {
  32. float num = Time.time - this._emitTime;
  33. float num2 = this.SizeFunction(num - DetonatorBurstEmitter.epsilon);
  34. float num3 = this.SizeFunction(num);
  35. float num4 = (num3 / num2 - 1f) / DetonatorBurstEmitter.epsilon;
  36. this._particleAnimator.sizeGrow = num4;
  37. }
  38. else
  39. {
  40. this._particleAnimator.sizeGrow = this.sizeGrow;
  41. }
  42. if (this._delayedExplosionStarted)
  43. {
  44. this._explodeDelay -= Time.deltaTime;
  45. if (this._explodeDelay <= 0f)
  46. {
  47. this.Explode();
  48. }
  49. }
  50. }
  51. private float SizeFunction(float elapsedTime)
  52. {
  53. float num = 1f - 1f / (1f + elapsedTime * this.speed);
  54. return this.initFraction + (1f - this.initFraction) * num;
  55. }
  56. public void Reset()
  57. {
  58. this.size = this._baseSize;
  59. this.color = this._baseColor;
  60. this.damping = this._baseDamping;
  61. }
  62. public override void Explode()
  63. {
  64. if (this.on)
  65. {
  66. this._particleEmitter.useWorldSpace = this.useWorldSpace;
  67. this._scaledDuration = this.timeScale * this.duration;
  68. this._scaledDurationVariation = this.timeScale * this.durationVariation;
  69. this._scaledStartRadius = this.size * this.startRadius;
  70. this._particleRenderer.particleRenderMode = this.renderMode;
  71. if (!this._delayedExplosionStarted)
  72. {
  73. this._explodeDelay = this.explodeDelayMin + UnityEngine.Random.value * (this.explodeDelayMax - this.explodeDelayMin);
  74. }
  75. if (this._explodeDelay <= 0f)
  76. {
  77. Color[] array = this._particleAnimator.colorAnimation;
  78. if (this.useExplicitColorAnimation)
  79. {
  80. array[0] = this.colorAnimation[0];
  81. array[1] = this.colorAnimation[1];
  82. array[2] = this.colorAnimation[2];
  83. array[3] = this.colorAnimation[3];
  84. array[4] = this.colorAnimation[4];
  85. }
  86. else
  87. {
  88. array[0] = new Color(this.color.r, this.color.g, this.color.b, this.color.a * 0.7f);
  89. array[1] = new Color(this.color.r, this.color.g, this.color.b, this.color.a * 1f);
  90. array[2] = new Color(this.color.r, this.color.g, this.color.b, this.color.a * 0.5f);
  91. array[3] = new Color(this.color.r, this.color.g, this.color.b, this.color.a * 0.3f);
  92. array[4] = new Color(this.color.r, this.color.g, this.color.b, this.color.a * 0f);
  93. }
  94. this._particleAnimator.colorAnimation = array;
  95. this._particleRenderer.material = this.material;
  96. this._particleAnimator.force = this.force;
  97. this._tmpCount = this.count * this.detail;
  98. if (this._tmpCount < 1f)
  99. {
  100. this._tmpCount = 1f;
  101. }
  102. if (this._particleEmitter.useWorldSpace)
  103. {
  104. this._thisPos = base.gameObject.transform.position;
  105. }
  106. else
  107. {
  108. this._thisPos = new Vector3(0f, 0f, 0f);
  109. }
  110. int num = 1;
  111. while ((float)num <= this._tmpCount)
  112. {
  113. this._tmpPos = Vector3.Scale(UnityEngine.Random.insideUnitSphere, new Vector3(this._scaledStartRadius, this._scaledStartRadius, this._scaledStartRadius));
  114. this._tmpPos = this._thisPos + this._tmpPos;
  115. this._tmpDir = Vector3.Scale(UnityEngine.Random.insideUnitSphere, new Vector3(this.velocity.x, this.velocity.y, this.velocity.z));
  116. this._tmpDir.y = this._tmpDir.y + 2f * (Mathf.Abs(this._tmpDir.y) * this.upwardsBias);
  117. if (this.randomRotation)
  118. {
  119. this._randomizedRotation = UnityEngine.Random.Range(-1f, 1f);
  120. this._tmpAngularVelocity = UnityEngine.Random.Range(-1f, 1f) * this.angularVelocity;
  121. }
  122. else
  123. {
  124. this._randomizedRotation = 0f;
  125. this._tmpAngularVelocity = this.angularVelocity;
  126. }
  127. this._tmpDir = Vector3.Scale(this._tmpDir, new Vector3(this.size, this.size, this.size));
  128. this._tmpParticleSize = this.size * (this.particleSize + UnityEngine.Random.value * this.sizeVariation);
  129. this._tmpDuration = this._scaledDuration + UnityEngine.Random.value * this._scaledDurationVariation;
  130. this._particleEmitter.Emit(this._tmpPos, this._tmpDir, this._tmpParticleSize, this._tmpDuration, this.color, this._randomizedRotation, this._tmpAngularVelocity);
  131. num++;
  132. }
  133. this._emitTime = Time.time;
  134. this._delayedExplosionStarted = false;
  135. this._explodeDelay = 0f;
  136. }
  137. else
  138. {
  139. this._delayedExplosionStarted = true;
  140. }
  141. }
  142. }
  143. private ParticleEmitter _particleEmitter;
  144. private ParticleRenderer _particleRenderer;
  145. private ParticleAnimator _particleAnimator;
  146. private float _baseDamping = 0.1300004f;
  147. private float _baseSize = 1f;
  148. private Color _baseColor = Color.white;
  149. public float damping = 1f;
  150. public float startRadius = 1f;
  151. public float maxScreenSize = 2f;
  152. public bool explodeOnAwake;
  153. public bool oneShot = true;
  154. public float sizeVariation;
  155. public float particleSize = 1f;
  156. public float count = 1f;
  157. public float sizeGrow = 20f;
  158. public bool exponentialGrowth = true;
  159. public float durationVariation;
  160. public bool useWorldSpace = true;
  161. public float upwardsBias;
  162. public float angularVelocity = 20f;
  163. public bool randomRotation = true;
  164. public ParticleRenderMode renderMode;
  165. public bool useExplicitColorAnimation;
  166. public Color[] colorAnimation = new Color[5];
  167. private bool _delayedExplosionStarted;
  168. private float _explodeDelay;
  169. public Material material;
  170. private float _emitTime;
  171. private float speed = 3f;
  172. private float initFraction = 0.1f;
  173. private static float epsilon = 0.01f;
  174. private float _tmpParticleSize;
  175. private Vector3 _tmpPos;
  176. private Vector3 _tmpDir;
  177. private Vector3 _thisPos;
  178. private float _tmpDuration;
  179. private float _tmpCount;
  180. private float _scaledDuration;
  181. private float _scaledDurationVariation;
  182. private float _scaledStartRadius;
  183. private float _scaledColor;
  184. private float _randomizedRotation;
  185. private float _tmpAngularVelocity;
  186. }