quantum-space-buddies/QSB/TransformSync/PlayerHUDMarker.cs

67 lines
1.6 KiB
C#
Raw Normal View History

2020-08-22 17:08:25 +00:00
using OWML.Common;
using QSB.Utility;
2020-08-20 17:24:31 +00:00
using System;
using UnityEngine;
namespace QSB.TransformSync
{
2020-07-28 13:59:24 +00:00
public class PlayerHUDMarker : HUDDistanceMarker
{
2020-08-18 13:00:37 +00:00
private PlayerInfo _player;
private bool _isReady;
protected override void InitCanvasMarker()
{
_markerRadius = 2f;
_markerTarget = new GameObject().transform;
_markerTarget.parent = transform;
_markerTarget.localPosition = Vector3.up * 2;
}
2020-08-08 10:25:09 +00:00
public void Init(PlayerInfo player)
{
2020-08-08 10:25:09 +00:00
_player = player;
2020-08-18 19:31:14 +00:00
_player.HudMarker = this;
_isReady = true;
}
protected override void RefreshOwnVisibility()
{
if (_canvasMarker != null)
{
_canvasMarker.SetVisibility(true);
}
}
2020-07-28 13:59:24 +00:00
private void Update()
{
2020-08-08 10:25:09 +00:00
if (!_isReady || !_player.IsReady)
{
2020-07-28 13:59:24 +00:00
return;
}
2020-08-08 10:25:09 +00:00
_markerLabel = _player.Name;
2020-07-28 13:59:24 +00:00
_isReady = false;
base.InitCanvasMarker();
}
2020-08-18 20:37:27 +00:00
public void Remove()
{
2020-08-20 16:29:47 +00:00
// do N O T destroy the parent - it completely breaks the ENTIRE GAME
2020-08-20 17:24:31 +00:00
try
2020-08-20 16:29:47 +00:00
{
_canvasMarker.DestroyMarker();
2020-08-20 17:24:31 +00:00
Destroy(_markerTarget.gameObject);
Destroy(this);
}
catch (Exception ex)
{
2020-08-22 17:08:25 +00:00
DebugLog.ToConsole($"Warning - Failed to remove PlayerHUDMarker for {_player.Name} ({_player.NetId}) : {ex}", MessageType.Warning);
2020-08-20 16:29:47 +00:00
}
2020-08-18 20:37:27 +00:00
}
}
}