DetonatorHeatwave.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using UnityEngine;
  3. [RequireComponent(typeof(Detonator))]
  4. [AddComponentMenu("Detonator/Heatwave (Pro Only)")]
  5. public class DetonatorHeatwave : DetonatorComponent
  6. {
  7. public override void Init()
  8. {
  9. }
  10. private void Update()
  11. {
  12. if (this._delayedExplosionStarted)
  13. {
  14. this._explodeDelay -= Time.deltaTime;
  15. if (this._explodeDelay <= 0f)
  16. {
  17. this.Explode();
  18. }
  19. }
  20. if (this._heatwave)
  21. {
  22. this._heatwave.transform.rotation = Quaternion.FromToRotation(Vector3.up, Camera.main.transform.position - this._heatwave.transform.position);
  23. this._heatwave.transform.localPosition = this.localPosition + Vector3.forward * this.zOffset;
  24. this._elapsedTime += Time.deltaTime;
  25. this._normalizedTime = this._elapsedTime / this.duration;
  26. this.s = Mathf.Lerp(this._startSize, this._maxSize, this._normalizedTime);
  27. this._heatwave.GetComponent<Renderer>().material.SetFloat("_BumpAmt", (1f - this._normalizedTime) * this.distortion);
  28. this._heatwave.gameObject.transform.localScale = new Vector3(this.s, this.s, this.s);
  29. if (this._elapsedTime > this.duration)
  30. {
  31. UnityEngine.Object.Destroy(this._heatwave.gameObject);
  32. }
  33. }
  34. }
  35. public override void Explode()
  36. {
  37. if (SystemInfo.supportsImageEffects)
  38. {
  39. if (this.detailThreshold > this.detail || !this.on)
  40. {
  41. return;
  42. }
  43. if (!this._delayedExplosionStarted)
  44. {
  45. this._explodeDelay = this.explodeDelayMin + UnityEngine.Random.value * (this.explodeDelayMax - this.explodeDelayMin);
  46. }
  47. if (this._explodeDelay <= 0f)
  48. {
  49. this._startSize = 0f;
  50. this._maxSize = this.size * 10f;
  51. this._material = new Material(Shader.Find("HeatDistort"));
  52. this._heatwave = GameObject.CreatePrimitive(PrimitiveType.Plane);
  53. this._heatwave.name = "Heatwave";
  54. this._heatwave.transform.parent = base.transform;
  55. UnityEngine.Object.Destroy(this._heatwave.GetComponent(typeof(MeshCollider)));
  56. if (!this.heatwaveMaterial)
  57. {
  58. this.heatwaveMaterial = base.MyDetonator().heatwaveMaterial;
  59. }
  60. this._material.CopyPropertiesFromMaterial(this.heatwaveMaterial);
  61. this._heatwave.GetComponent<Renderer>().material = this._material;
  62. this._heatwave.transform.parent = base.transform;
  63. this._delayedExplosionStarted = false;
  64. this._explodeDelay = 0f;
  65. }
  66. else
  67. {
  68. this._delayedExplosionStarted = true;
  69. }
  70. }
  71. }
  72. public void Reset()
  73. {
  74. this.duration = this._baseDuration;
  75. }
  76. private GameObject _heatwave;
  77. private float s;
  78. private float _startSize;
  79. private float _maxSize;
  80. private float _baseDuration = 0.25f;
  81. private bool _delayedExplosionStarted;
  82. private float _explodeDelay;
  83. public float zOffset = 0.5f;
  84. public float distortion = 64f;
  85. private float _elapsedTime;
  86. private float _normalizedTime;
  87. public Material heatwaveMaterial;
  88. private Material _material;
  89. }