DetonatorShockwave.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System;
  2. using UnityEngine;
  3. [RequireComponent(typeof(Detonator))]
  4. [AddComponentMenu("Detonator/Shockwave")]
  5. public class DetonatorShockwave : DetonatorComponent
  6. {
  7. public override void Init()
  8. {
  9. this.FillMaterials(false);
  10. this.BuildShockwave();
  11. }
  12. public void FillMaterials(bool wipe)
  13. {
  14. if (!this.shockwaveMaterial || wipe)
  15. {
  16. this.shockwaveMaterial = base.MyDetonator().shockwaveMaterial;
  17. }
  18. }
  19. public void BuildShockwave()
  20. {
  21. this._shockwave = new GameObject("Shockwave");
  22. this._shockwaveEmitter = this._shockwave.AddComponent<DetonatorBurstEmitter>();
  23. this._shockwave.transform.parent = base.transform;
  24. this._shockwave.transform.localRotation = Quaternion.identity;
  25. this._shockwave.transform.localPosition = this.localPosition;
  26. this._shockwaveEmitter.material = this.shockwaveMaterial;
  27. this._shockwaveEmitter.exponentialGrowth = false;
  28. this._shockwaveEmitter.useWorldSpace = base.MyDetonator().useWorldSpace;
  29. }
  30. public void UpdateShockwave()
  31. {
  32. this._shockwave.transform.localPosition = Vector3.Scale(this.localPosition, new Vector3(this.size, this.size, this.size));
  33. this._shockwaveEmitter.color = this.color;
  34. this._shockwaveEmitter.duration = this.duration;
  35. this._shockwaveEmitter.durationVariation = this.duration * 0.1f;
  36. this._shockwaveEmitter.count = 1f;
  37. this._shockwaveEmitter.detail = 1f;
  38. this._shockwaveEmitter.particleSize = 25f;
  39. this._shockwaveEmitter.sizeVariation = 0f;
  40. this._shockwaveEmitter.velocity = new Vector3(0f, 0f, 0f);
  41. this._shockwaveEmitter.startRadius = 0f;
  42. this._shockwaveEmitter.sizeGrow = 202f;
  43. this._shockwaveEmitter.size = this.size;
  44. this._shockwaveEmitter.explodeDelayMin = this.explodeDelayMin;
  45. this._shockwaveEmitter.explodeDelayMax = this.explodeDelayMax;
  46. this._shockwaveEmitter.renderMode = this.renderMode;
  47. }
  48. public void Reset()
  49. {
  50. this.FillMaterials(true);
  51. this.on = true;
  52. this.size = this._baseSize;
  53. this.duration = this._baseDuration;
  54. this.explodeDelayMin = 0f;
  55. this.explodeDelayMax = 0f;
  56. this.color = this._baseColor;
  57. this.velocity = this._baseVelocity;
  58. }
  59. public override void Explode()
  60. {
  61. if (this.on)
  62. {
  63. this.UpdateShockwave();
  64. this._shockwaveEmitter.Explode();
  65. }
  66. }
  67. private float _baseSize = 1f;
  68. private float _baseDuration = 0.25f;
  69. private Vector3 _baseVelocity = new Vector3(0f, 0f, 0f);
  70. private Color _baseColor = Color.white;
  71. private GameObject _shockwave;
  72. private DetonatorBurstEmitter _shockwaveEmitter;
  73. public Material shockwaveMaterial;
  74. public ParticleRenderMode renderMode;
  75. }