DetonatorCloudRing.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using UnityEngine;
  3. [RequireComponent(typeof(Detonator))]
  4. public class DetonatorCloudRing : DetonatorComponent
  5. {
  6. public override void Init()
  7. {
  8. this.FillMaterials(false);
  9. this.BuildCloudRing();
  10. }
  11. public void FillMaterials(bool wipe)
  12. {
  13. if (!this.cloudRingMaterial || wipe)
  14. {
  15. this.cloudRingMaterial = base.MyDetonator().smokeBMaterial;
  16. }
  17. }
  18. public void BuildCloudRing()
  19. {
  20. this._cloudRing = new GameObject("CloudRing");
  21. this._cloudRingEmitter = this._cloudRing.AddComponent<DetonatorBurstEmitter>();
  22. this._cloudRing.transform.parent = base.transform;
  23. this._cloudRing.transform.localPosition = this.localPosition;
  24. this._cloudRingEmitter.material = this.cloudRingMaterial;
  25. this._cloudRingEmitter.useExplicitColorAnimation = true;
  26. }
  27. public void UpdateCloudRing()
  28. {
  29. this._cloudRing.transform.localPosition = Vector3.Scale(this.localPosition, new Vector3(this.size, this.size, this.size));
  30. this._cloudRingEmitter.color = this.color;
  31. this._cloudRingEmitter.duration = this.duration;
  32. this._cloudRingEmitter.durationVariation = this.duration / 4f;
  33. this._cloudRingEmitter.count = (float)((int)(this.detail * 50f));
  34. this._cloudRingEmitter.particleSize = 10f;
  35. this._cloudRingEmitter.sizeVariation = 2f;
  36. this._cloudRingEmitter.velocity = this.velocity;
  37. this._cloudRingEmitter.startRadius = 3f;
  38. this._cloudRingEmitter.size = this.size;
  39. this._cloudRingEmitter.force = this.force;
  40. this._cloudRingEmitter.explodeDelayMin = this.explodeDelayMin;
  41. this._cloudRingEmitter.explodeDelayMax = this.explodeDelayMax;
  42. Color color = Color.Lerp(this.color, new Color(0.2f, 0.2f, 0.2f, 0.6f), 0.5f);
  43. Color color2 = new Color(0.2f, 0.2f, 0.2f, 0.5f);
  44. Color color3 = new Color(0.2f, 0.2f, 0.2f, 0.3f);
  45. Color color4 = new Color(0.2f, 0.2f, 0.2f, 0f);
  46. this._cloudRingEmitter.colorAnimation[0] = color;
  47. this._cloudRingEmitter.colorAnimation[1] = color2;
  48. this._cloudRingEmitter.colorAnimation[2] = color2;
  49. this._cloudRingEmitter.colorAnimation[3] = color3;
  50. this._cloudRingEmitter.colorAnimation[4] = color4;
  51. }
  52. public void Reset()
  53. {
  54. this.FillMaterials(true);
  55. this.on = true;
  56. this.size = this._baseSize;
  57. this.duration = this._baseDuration;
  58. this.explodeDelayMin = 0f;
  59. this.explodeDelayMax = 0f;
  60. this.color = this._baseColor;
  61. this.velocity = this._baseVelocity;
  62. this.force = this._baseForce;
  63. }
  64. public override void Explode()
  65. {
  66. if (this.on)
  67. {
  68. this.UpdateCloudRing();
  69. this._cloudRingEmitter.Explode();
  70. }
  71. }
  72. private float _baseSize = 1f;
  73. private float _baseDuration = 5f;
  74. private Vector3 _baseVelocity = new Vector3(155f, 5f, 155f);
  75. private Color _baseColor = Color.white;
  76. private Vector3 _baseForce = new Vector3(0.162f, 2.56f, 0f);
  77. private GameObject _cloudRing;
  78. private DetonatorBurstEmitter _cloudRingEmitter;
  79. public Material cloudRingMaterial;
  80. }