DetonatorGlow.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System;
  2. using UnityEngine;
  3. [RequireComponent(typeof(Detonator))]
  4. [AddComponentMenu("Detonator/Glow")]
  5. public class DetonatorGlow : DetonatorComponent
  6. {
  7. public override void Init()
  8. {
  9. this.FillMaterials(false);
  10. this.BuildGlow();
  11. }
  12. public void FillMaterials(bool wipe)
  13. {
  14. if (!this.glowMaterial || wipe)
  15. {
  16. this.glowMaterial = base.MyDetonator().glowMaterial;
  17. }
  18. }
  19. public void BuildGlow()
  20. {
  21. this._glow = new GameObject("Glow");
  22. this._glowEmitter = this._glow.AddComponent<DetonatorBurstEmitter>();
  23. this._glow.transform.parent = base.transform;
  24. this._glow.transform.localPosition = this.localPosition;
  25. this._glowEmitter.material = this.glowMaterial;
  26. this._glowEmitter.exponentialGrowth = false;
  27. this._glowEmitter.useExplicitColorAnimation = true;
  28. this._glowEmitter.useWorldSpace = base.MyDetonator().useWorldSpace;
  29. }
  30. public void UpdateGlow()
  31. {
  32. this._glow.transform.localPosition = Vector3.Scale(this.localPosition, new Vector3(this.size, this.size, this.size));
  33. this._glowEmitter.color = this.color;
  34. this._glowEmitter.duration = this.duration;
  35. this._glowEmitter.timeScale = this.timeScale;
  36. this._glowEmitter.count = 1f;
  37. this._glowEmitter.particleSize = 65f;
  38. this._glowEmitter.randomRotation = false;
  39. this._glowEmitter.sizeVariation = 0f;
  40. this._glowEmitter.velocity = new Vector3(0f, 0f, 0f);
  41. this._glowEmitter.startRadius = 0f;
  42. this._glowEmitter.sizeGrow = 0f;
  43. this._glowEmitter.size = this.size;
  44. this._glowEmitter.explodeDelayMin = this.explodeDelayMin;
  45. this._glowEmitter.explodeDelayMax = this.explodeDelayMax;
  46. Color color = Color.Lerp(this.color, new Color(0.5f, 0.1f, 0.1f, 1f), 0.5f);
  47. color.a = 0.9f;
  48. Color color2 = Color.Lerp(this.color, new Color(0.6f, 0.3f, 0.3f, 1f), 0.5f);
  49. color2.a = 0.8f;
  50. Color color3 = Color.Lerp(this.color, new Color(0.7f, 0.3f, 0.3f, 1f), 0.5f);
  51. color3.a = 0.5f;
  52. Color color4 = Color.Lerp(this.color, new Color(0.4f, 0.3f, 0.4f, 1f), 0.5f);
  53. color4.a = 0.2f;
  54. Color color5 = new Color(0.1f, 0.1f, 0.4f, 0f);
  55. this._glowEmitter.colorAnimation[0] = color;
  56. this._glowEmitter.colorAnimation[1] = color2;
  57. this._glowEmitter.colorAnimation[2] = color3;
  58. this._glowEmitter.colorAnimation[3] = color4;
  59. this._glowEmitter.colorAnimation[4] = color5;
  60. }
  61. private void Update()
  62. {
  63. }
  64. public void Reset()
  65. {
  66. this.FillMaterials(true);
  67. this.on = true;
  68. this.size = this._baseSize;
  69. this.duration = this._baseDuration;
  70. this.explodeDelayMin = 0f;
  71. this.explodeDelayMax = 0f;
  72. this.color = this._baseColor;
  73. this.velocity = this._baseVelocity;
  74. }
  75. public override void Explode()
  76. {
  77. if (this.detailThreshold > this.detail)
  78. {
  79. return;
  80. }
  81. if (this.on)
  82. {
  83. this.UpdateGlow();
  84. this._glowEmitter.Explode();
  85. }
  86. }
  87. private float _baseSize = 1f;
  88. private float _baseDuration = 1f;
  89. private Vector3 _baseVelocity = new Vector3(0f, 0f, 0f);
  90. private Color _baseColor = Color.black;
  91. private float _scaledDuration;
  92. private GameObject _glow;
  93. private DetonatorBurstEmitter _glowEmitter;
  94. public Material glowMaterial;
  95. }