quantum-space-buddies/QSB/RespawnSync/RespawnHUDMarker.cs

50 lines
1.0 KiB
C#
Raw Normal View History

using QSB.Localization;
2022-06-04 15:19:55 +00:00
using QSB.ShipSync;
using UnityEngine;
2021-11-18 11:34:14 +00:00
2022-03-03 03:46:33 +00:00
namespace QSB.RespawnSync;
public class RespawnHUDMarker : HUDDistanceMarker
2021-11-18 11:34:14 +00:00
{
2022-03-03 03:46:33 +00:00
private bool _isReady;
public override void InitCanvasMarker()
2021-11-18 11:34:14 +00:00
{
2022-03-03 03:46:33 +00:00
_markerRadius = 0.2f;
_markerTarget = transform;
_markerLabel = QSBLocalization.Current.RespawnPlayer.ToUpper();
2022-03-03 03:46:33 +00:00
_isReady = true;
2021-11-18 11:34:14 +00:00
2022-03-03 03:46:33 +00:00
base.InitCanvasMarker();
}
2022-03-03 03:46:33 +00:00
private void Update()
{
if (!_isReady)
{
return;
2021-11-18 11:34:14 +00:00
}
2022-03-03 03:46:33 +00:00
if (_canvasMarker != null)
2021-11-18 11:34:14 +00:00
{
2022-03-03 03:46:33 +00:00
var isVisible = _canvasMarker.IsVisible();
var shouldBeVisible = RespawnManager.Instance.RespawnNeeded
&& !ShipManager.Instance.IsShipWrecked;
2021-11-18 11:34:14 +00:00
if (shouldBeVisible != isVisible)
2021-11-18 11:34:14 +00:00
{
_isVisible = shouldBeVisible;
2022-03-03 03:46:33 +00:00
_canvasMarker.SetVisibility(_isVisible);
2021-11-18 11:34:14 +00:00
}
2022-03-03 03:46:33 +00:00
}
2021-11-18 11:34:14 +00:00
2022-03-03 03:46:33 +00:00
if (_isVisible && _canvasMarker != null)
{
var color = (Mathf.Sin(Time.unscaledTime * 10f) > 0f)
? Color.white
: new Color(1f, 1f, 1f, 0.1f);
_canvasMarker._mainTextField.color = color;
_canvasMarker._offScreenIndicator._textField.color = color;
2021-11-18 11:34:14 +00:00
}
}
}