70 lines
1.7 KiB
C#
Raw Normal View History

2021-07-04 22:34:38 +01:00
using QSB.Utility;
using QSB.WorldSync;
2021-07-04 16:46:51 +01:00
using System.Linq;
2021-07-04 22:34:38 +01:00
using UnityEngine;
2021-07-04 16:46:51 +01:00
2022-03-02 19:46:33 -08:00
namespace QSB.Tools.ProbeTool;
2022-08-27 11:44:52 -07:00
[UsedInUnityProject]
2022-03-02 19:46:33 -08:00
internal class QSBProbeEffects : MonoBehaviour
2021-07-04 16:46:51 +01:00
{
2022-03-02 19:46:33 -08:00
public OWAudioSource _flightLoopAudio;
public OWAudioSource _anchorAudio;
public ParticleSystem _anchorParticles;
2021-07-04 16:46:51 +01:00
2022-08-27 11:30:15 -07:00
private QSBSurveyorProbe _probe;
2021-07-04 16:46:51 +01:00
2022-03-02 19:46:33 -08:00
private void Awake()
{
2022-08-27 11:30:15 -07:00
_probe = QSBWorldSync.GetUnityObjects<QSBSurveyorProbe>().First(x => gameObject.transform.IsChildOf(x.transform));
2022-03-02 19:46:33 -08:00
if (_probe == null)
{
2022-03-02 19:46:33 -08:00
DebugLog.ToConsole($"Error - Couldn't find QSBProbe!", OWML.Common.MessageType.Error);
}
2021-07-04 16:46:51 +01:00
2022-03-02 19:46:33 -08:00
_probe.OnLaunchProbe += OnLaunch;
_probe.OnAnchorProbe += OnAnchor;
_probe.OnUnanchorProbe += OnUnanchor;
_probe.OnStartRetrieveProbe += OnStartRetrieve;
_probe.OnTakeSnapshot += OnTakeSnapshot;
2022-03-02 19:46:33 -08:00
}
2021-07-04 16:46:51 +01:00
2022-03-02 19:46:33 -08:00
private void OnDestroy()
{
_probe.OnLaunchProbe -= OnLaunch;
_probe.OnAnchorProbe -= OnAnchor;
_probe.OnUnanchorProbe -= OnUnanchor;
_probe.OnStartRetrieveProbe -= OnStartRetrieve;
_probe.OnTakeSnapshot -= OnTakeSnapshot;
2022-03-02 19:46:33 -08:00
}
2022-03-02 19:46:33 -08:00
private void OnLaunch() => _flightLoopAudio.FadeIn(0.1f, true, true);
2022-03-02 19:46:33 -08:00
private void OnAnchor()
{
// TODO : Come up with some other way of doing this
//if (this._fluidDetector.InFluidType(FluidVolume.Type.WATER))
//{
// this._underwaterAnchorParticles.Play();
//}
//else
//{
_anchorParticles.Play();
//}
_flightLoopAudio.FadeOut(0.5f);
_anchorAudio.PlayOneShot(AudioType.ToolProbeAttach);
}
2022-03-02 19:46:33 -08:00
private void OnUnanchor()
=> _flightLoopAudio.FadeIn(0.5f);
private void OnStartRetrieve(float retrieveLength)
{
_flightLoopAudio.FadeOut(retrieveLength);
_anchorAudio.PlayOneShot(AudioType.ToolProbeRetrieve);
}
private void OnTakeSnapshot()
=> _anchorAudio.PlayOneShot(AudioType.ToolProbeTakePhoto);
}