2020-11-04 09:09:50 +00:00
|
|
|
|
using UnityEngine;
|
2020-05-19 19:41:33 +02:00
|
|
|
|
|
2020-11-03 22:29:23 +00:00
|
|
|
|
namespace QSB.Player
|
2020-05-19 19:41:33 +02:00
|
|
|
|
{
|
2020-07-28 15:59:24 +02:00
|
|
|
|
public class PlayerHUDMarker : HUDDistanceMarker
|
2020-05-19 19:41:33 +02:00
|
|
|
|
{
|
2020-08-18 14:00:37 +01:00
|
|
|
|
private PlayerInfo _player;
|
2020-05-19 19:41:33 +02:00
|
|
|
|
private bool _isReady;
|
|
|
|
|
|
|
|
|
|
protected override void InitCanvasMarker()
|
|
|
|
|
{
|
2020-07-28 00:13:43 +01:00
|
|
|
|
_markerRadius = 2f;
|
2020-05-19 19:41:33 +02:00
|
|
|
|
|
|
|
|
|
_markerTarget = new GameObject().transform;
|
|
|
|
|
_markerTarget.parent = transform;
|
2020-07-28 00:13:43 +01:00
|
|
|
|
|
2020-08-08 13:53:57 +01:00
|
|
|
|
_markerTarget.localPosition = Vector3.up * 2;
|
2020-05-19 19:41:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-08 12:25:09 +02:00
|
|
|
|
public void Init(PlayerInfo player)
|
2020-05-19 19:41:33 +02:00
|
|
|
|
{
|
2020-08-08 12:25:09 +02:00
|
|
|
|
_player = player;
|
2020-08-18 21:31:14 +02:00
|
|
|
|
_player.HudMarker = this;
|
2020-05-19 19:41:33 +02:00
|
|
|
|
_isReady = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void RefreshOwnVisibility()
|
|
|
|
|
{
|
|
|
|
|
if (_canvasMarker != null)
|
|
|
|
|
{
|
|
|
|
|
_canvasMarker.SetVisibility(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-28 15:59:24 +02:00
|
|
|
|
private void Update()
|
2020-05-19 19:41:33 +02:00
|
|
|
|
{
|
2020-08-08 12:25:09 +02:00
|
|
|
|
if (!_isReady || !_player.IsReady)
|
2020-05-19 19:41:33 +02:00
|
|
|
|
{
|
2020-07-28 15:59:24 +02:00
|
|
|
|
return;
|
2020-05-19 19:41:33 +02:00
|
|
|
|
}
|
2020-08-24 16:00:37 +01:00
|
|
|
|
_markerLabel = _player.Name.ToUpper();
|
2020-07-28 15:59:24 +02:00
|
|
|
|
_isReady = false;
|
|
|
|
|
|
|
|
|
|
base.InitCanvasMarker();
|
2020-05-19 19:41:33 +02:00
|
|
|
|
}
|
2020-08-18 22:37:27 +02:00
|
|
|
|
|
|
|
|
|
public void Remove()
|
|
|
|
|
{
|
2020-08-20 17:29:47 +01:00
|
|
|
|
// do N O T destroy the parent - it completely breaks the ENTIRE GAME
|
2020-08-23 21:01:09 +02:00
|
|
|
|
if (_canvasMarker?.gameObject != null)
|
2020-08-20 17:29:47 +01:00
|
|
|
|
{
|
|
|
|
|
_canvasMarker.DestroyMarker();
|
2020-08-20 18:24:31 +01:00
|
|
|
|
}
|
2020-08-23 21:01:09 +02:00
|
|
|
|
Destroy(_markerTarget.gameObject);
|
|
|
|
|
Destroy(this);
|
2020-08-18 22:37:27 +02:00
|
|
|
|
}
|
2020-08-23 21:01:09 +02:00
|
|
|
|
|
2020-05-19 19:41:33 +02:00
|
|
|
|
}
|
|
|
|
|
}
|