2021-07-04 10:32:59 +00:00
|
|
|
|
using QSB.Utility;
|
2021-11-14 11:51:22 +00:00
|
|
|
|
using QSB.WorldSync;
|
2021-07-04 15:25:39 +00:00
|
|
|
|
using System.Linq;
|
2021-07-03 23:00:24 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2021-11-09 17:46:46 +00:00
|
|
|
|
namespace QSB.Tools.ProbeTool
|
2021-07-03 23:00:24 +00:00
|
|
|
|
{
|
2021-07-12 21:02:50 +00:00
|
|
|
|
internal class QSBProbeSpotlight : MonoBehaviour
|
2021-07-03 23:00:24 +00:00
|
|
|
|
{
|
|
|
|
|
public ProbeCamera.ID _id;
|
|
|
|
|
public float _fadeInLength = 1f;
|
2021-07-05 20:08:25 +00:00
|
|
|
|
public float _intensity;
|
2021-07-03 23:00:24 +00:00
|
|
|
|
|
|
|
|
|
private QSBProbe _probe;
|
|
|
|
|
private OWLight2 _light;
|
|
|
|
|
private float _timer;
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
2021-11-14 11:51:22 +00:00
|
|
|
|
_probe = QSBWorldSync.GetUnityObjects<QSBProbe>().First(x => gameObject.transform.IsChildOf(x.transform));
|
2021-07-04 15:25:39 +00:00
|
|
|
|
if (_probe == null)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Error - Couldn't find QSBProbe!", OWML.Common.MessageType.Error);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-03 23:00:24 +00:00
|
|
|
|
_light = GetComponent<OWLight2>();
|
2021-07-05 20:08:25 +00:00
|
|
|
|
//_intensity = _light.GetLight().intensity;
|
2021-07-03 23:00:24 +00:00
|
|
|
|
_light.GetLight().enabled = false;
|
|
|
|
|
enabled = false;
|
|
|
|
|
_probe.OnLaunchProbe += OnLaunch;
|
|
|
|
|
_probe.OnAnchorProbe += OnAnchorOrRetrieve;
|
|
|
|
|
_probe.OnRetrieveProbe += OnAnchorOrRetrieve;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
|
{
|
|
|
|
|
_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()
|
|
|
|
|
{
|
|
|
|
|
if (!enabled)
|
|
|
|
|
{
|
|
|
|
|
_light.GetLight().enabled = true;
|
|
|
|
|
_light.SetIntensityScale(0f);
|
|
|
|
|
_timer = 0f;
|
|
|
|
|
enabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnLaunch()
|
|
|
|
|
{
|
|
|
|
|
if (_id == ProbeCamera.ID.Forward)
|
|
|
|
|
{
|
|
|
|
|
StartFadeIn();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAnchorOrRetrieve()
|
|
|
|
|
{
|
|
|
|
|
_light.GetLight().enabled = false;
|
|
|
|
|
enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|