DetonatorLight.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using UnityEngine;
  3. [RequireComponent(typeof(Detonator))]
  4. [AddComponentMenu("Detonator/Light")]
  5. public class DetonatorLight : DetonatorComponent
  6. {
  7. public override void Init()
  8. {
  9. this._light = new GameObject("Light");
  10. this._light.transform.parent = base.transform;
  11. this._light.transform.localPosition = this.localPosition;
  12. this._lightComponent = this._light.AddComponent<Light>();
  13. this._lightComponent.type = LightType.Point;
  14. this._lightComponent.enabled = false;
  15. }
  16. private void Update()
  17. {
  18. if (this._explodeTime + this._scaledDuration > Time.time && this._lightComponent.intensity > 0f)
  19. {
  20. this._reduceAmount = this.intensity * (Time.deltaTime / this._scaledDuration);
  21. this._lightComponent.intensity -= this._reduceAmount;
  22. }
  23. else if (this._lightComponent)
  24. {
  25. this._lightComponent.enabled = false;
  26. }
  27. }
  28. public override void Explode()
  29. {
  30. if (this.detailThreshold > this.detail)
  31. {
  32. return;
  33. }
  34. this._lightComponent.color = this.color;
  35. this._lightComponent.range = this.size * 50f;
  36. this._scaledDuration = this.duration * this.timeScale;
  37. this._lightComponent.enabled = true;
  38. this._lightComponent.intensity = this.intensity;
  39. this._explodeTime = Time.time;
  40. }
  41. public void Reset()
  42. {
  43. this.color = this._baseColor;
  44. this.intensity = this._baseIntensity;
  45. }
  46. private float _baseIntensity = 1f;
  47. private Color _baseColor = Color.white;
  48. private float _scaledDuration;
  49. private float _explodeTime = -1000f;
  50. private GameObject _light;
  51. private Light _lightComponent;
  52. public float intensity;
  53. private float _reduceAmount;
  54. }