quantum-space-buddies/QSB/ProbeSync/QSBProbeSpotlight.cs

78 lines
1.6 KiB
C#
Raw Normal View History

2021-07-04 10:32:59 +00:00
using QSB.Utility;
2021-07-03 23:00:24 +00:00
using UnityEngine;
namespace QSB.ProbeSync
{
class QSBProbeSpotlight : MonoBehaviour
{
public ProbeCamera.ID _id;
public float _fadeInLength = 1f;
private QSBProbe _probe;
private OWLight2 _light;
private bool _inFlight;
private float _intensity;
private float _timer;
private void Awake()
{
2021-07-04 10:32:59 +00:00
DebugLog.DebugWrite("Awake");
2021-07-03 23:00:24 +00:00
_probe = this.GetRequiredComponentInChildren<QSBProbe>();
_light = GetComponent<OWLight2>();
_intensity = _light.GetLight().intensity;
_light.GetLight().enabled = false;
enabled = false;
_probe.OnLaunchProbe += OnLaunch;
_probe.OnAnchorProbe += OnAnchorOrRetrieve;
_probe.OnRetrieveProbe += OnAnchorOrRetrieve;
}
private void OnDestroy()
{
2021-07-04 10:32:59 +00:00
DebugLog.DebugWrite("OnDestroy");
2021-07-03 23:00:24 +00:00
_probe.OnLaunchProbe -= OnLaunch;
_probe.OnAnchorProbe -= OnAnchorOrRetrieve;
_probe.OnRetrieveProbe -= OnAnchorOrRetrieve;
}
private void Update()
{
_timer += Time.deltaTime;
var num = Mathf.Clamp01(_timer / _fadeInLength);
var intensityScale = (2f - num) * num * _intensity;
_light.SetIntensityScale(intensityScale);
}
private void StartFadeIn()
{
2021-07-04 10:32:59 +00:00
DebugLog.DebugWrite("StartFadeIn");
2021-07-03 23:00:24 +00:00
if (!enabled)
{
_light.GetLight().enabled = true;
_light.SetIntensityScale(0f);
_timer = 0f;
enabled = true;
}
}
private void OnLaunch()
{
2021-07-04 10:32:59 +00:00
DebugLog.DebugWrite("OnLaunch");
2021-07-03 23:00:24 +00:00
if (_id == ProbeCamera.ID.Forward)
{
StartFadeIn();
}
_inFlight = true;
}
private void OnAnchorOrRetrieve()
{
2021-07-04 10:32:59 +00:00
DebugLog.DebugWrite("OnAnchorOrRetrieve");
2021-07-03 23:00:24 +00:00
_light.GetLight().enabled = false;
enabled = false;
_inFlight = false;
}
}
}