137 lines
3.2 KiB
C#
Raw Normal View History

using QSB.Utility;
using UnityEngine;
2021-04-11 17:08:18 +01:00
namespace QSB.ProbeSync
{
2020-12-02 21:23:01 +00:00
public class QSBProbe : MonoBehaviour
{
2021-07-04 00:00:24 +01:00
public delegate void SurveyorProbeEvent();
public delegate void RetrieveEvent(float retrieveLength);
public event SurveyorProbeEvent OnLaunchProbe;
public event SurveyorProbeEvent OnAnchorProbe;
public event SurveyorProbeEvent OnUnanchorProbe;
public event SurveyorProbeEvent OnRetrieveProbe;
public event SurveyorProbeEvent OnProbeDestroyed;
public event RetrieveEvent OnStartRetrieveProbe;
private GameObject _detectorObj;
private RulesetDetector _rulesetDetector;
2021-07-04 22:34:31 +01:00
private SingularityWarpEffect _warpEffect;
private bool _isRetrieving;
2021-07-04 00:00:24 +01:00
2021-07-04 22:34:31 +01:00
public RulesetDetector GetRulesetDetector()
2021-07-04 00:00:24 +01:00
=> _rulesetDetector;
private void Awake()
{
2021-07-04 16:03:45 +01:00
_detectorObj = GetComponentInChildren<RulesetDetector>().gameObject;
2021-07-04 00:00:24 +01:00
_rulesetDetector = _detectorObj.GetComponent<RulesetDetector>();
2021-07-04 22:34:31 +01:00
_warpEffect = GetComponentInChildren<SingularityWarpEffect>();
_warpEffect.OnWarpComplete += OnWarpComplete;
_isRetrieving = false;
}
private void OnDestroy()
{
_warpEffect.OnWarpComplete -= OnWarpComplete;
}
private void OnWarpComplete()
{
DebugLog.DebugWrite($"OnWarpComplete");
//gameObject.SetActive(false);
transform.localScale = Vector3.one;
_isRetrieving = false;
}
public bool IsRetrieving()
{
return IsLaunched() && _isRetrieving;
}
public bool IsLaunched()
{
return gameObject.activeSelf;
2021-07-04 00:00:24 +01:00
}
2021-07-04 16:03:45 +01:00
public void HandleEvent(ProbeEvent probeEvent)
{
switch (probeEvent)
{
case ProbeEvent.Launch:
if (OnLaunchProbe == null)
{
DebugLog.ToConsole($"Warning - OnLaunchProbe is null!", OWML.Common.MessageType.Warning);
break;
}
OnLaunchProbe();
break;
case ProbeEvent.Anchor:
if (OnAnchorProbe == null)
{
DebugLog.ToConsole($"Warning - OnAnchorProbe is null!", OWML.Common.MessageType.Warning);
break;
}
OnAnchorProbe();
break;
case ProbeEvent.Unanchor:
DebugLog.DebugWrite($"OnUnanchorProbe");
OnUnanchorProbe();
break;
case ProbeEvent.Retrieve:
if (OnRetrieveProbe == null)
{
DebugLog.ToConsole($"Warning - OnRetrieveProbe is null!", OWML.Common.MessageType.Warning);
break;
}
OnRetrieveProbe();
break;
case ProbeEvent.Destroy:
2021-07-04 19:10:50 +01:00
if (OnProbeDestroyed == null)
{
DebugLog.ToConsole($"Warning - OnProbeDestroyed is null!", OWML.Common.MessageType.Warning);
break;
}
2021-07-04 16:03:45 +01:00
OnProbeDestroyed();
break;
case ProbeEvent.Invalid:
default:
DebugLog.DebugWrite($"Warning - Unknown/Invalid probe event.", OWML.Common.MessageType.Warning);
break;
}
}
2021-07-04 22:34:31 +01:00
public void OnStartRetrieve(float duration)
{
DebugLog.DebugWrite($"OnStartRetrieving");
if (!_isRetrieving)
{
_isRetrieving = true;
DebugLog.DebugWrite($"start warp out");
_warpEffect.WarpObjectOut(duration);
if (_warpEffect.gameObject.activeInHierarchy == false)
{
DebugLog.DebugWrite($"warp effect GO is not active!");
}
}
}
2020-12-02 21:23:01 +00:00
public void SetState(bool state)
{
if (state)
{
2020-12-11 23:13:13 +00:00
gameObject.SetActive(true);
gameObject.Show();
return;
2020-12-02 21:23:01 +00:00
}
2021-06-18 22:38:32 +01:00
2020-12-02 21:23:01 +00:00
gameObject.Hide();
}
}
2020-12-03 08:28:05 +00:00
}