SFX_LightAnimator.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using UnityEngine;
  2. // ReSharper disable once CheckNamespace
  3. namespace QFX.SFX
  4. {
  5. [RequireComponent(typeof(Light))]
  6. public class SFX_LightAnimator : SFX_ControlledObject
  7. {
  8. public SFX_AnimationModule LightIntensity;
  9. private float _startedTime;
  10. private Light _light;
  11. public override void Run()
  12. {
  13. base.Run();
  14. _light.gameObject.SetActive(true);
  15. _startedTime = Time.time;
  16. _light.intensity = LightIntensity.Evaluate(0);
  17. }
  18. public override void Stop()
  19. {
  20. base.Stop();
  21. _light.gameObject.SetActive(false);
  22. }
  23. private void Awake()
  24. {
  25. _light = GetComponent<Light>();
  26. _light.intensity = LightIntensity.Evaluate(0);
  27. }
  28. private void Update()
  29. {
  30. if (!IsRunning)
  31. return;
  32. var time = Time.time - _startedTime;
  33. var lightIntensity = LightIntensity.Evaluate(time);
  34. _light.intensity = lightIntensity;
  35. }
  36. }
  37. }