mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-20 15:41:01 +00:00
add player map markers
This commit is contained in:
parent
a039cf222c
commit
62cc03f934
70
QSB/Player/PlayerMapMarker.cs
Normal file
70
QSB/Player/PlayerMapMarker.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Player
|
||||
{
|
||||
public class PlayerMapMarker : MonoBehaviour
|
||||
{
|
||||
public string PlayerName;
|
||||
private Transform _playerTransform;
|
||||
private CanvasMapMarker _canvasMarker;
|
||||
private bool _canvasMarkerInitialized;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
GlobalMessenger.AddListener("EnterMapView", new Callback(OnEnterMapView));
|
||||
GlobalMessenger.AddListener("ExitMapView", new Callback(OnExitMapView));
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
enabled = false;
|
||||
_playerTransform = Locator.GetPlayerTransform();
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
GlobalMessenger.RemoveListener("EnterMapView", new Callback(OnEnterMapView));
|
||||
GlobalMessenger.RemoveListener("ExitMapView", new Callback(OnExitMapView));
|
||||
}
|
||||
|
||||
public void InitMarker()
|
||||
{
|
||||
var obj = GameObject.FindWithTag("MapCamera");
|
||||
var markerManager = obj.GetRequiredComponent<MapController>().GetMarkerManager();
|
||||
_canvasMarker = markerManager.InstantiateNewMarker(true);
|
||||
var component = GetComponent<OWRigidbody>();
|
||||
if (component != null)
|
||||
{
|
||||
markerManager.RegisterMarker(_canvasMarker, component);
|
||||
}
|
||||
else
|
||||
{
|
||||
markerManager.RegisterMarker(_canvasMarker, transform);
|
||||
}
|
||||
_canvasMarker.SetLabel(PlayerName.ToUpper());
|
||||
_canvasMarker.SetColor(Color.white);
|
||||
_canvasMarker.SetVisibility(false);
|
||||
_canvasMarkerInitialized = true;
|
||||
}
|
||||
|
||||
private void OnEnterMapView() => enabled = true;
|
||||
private void OnExitMapView() => enabled = false;
|
||||
|
||||
public void LateUpdate()
|
||||
{
|
||||
if (!_canvasMarkerInitialized)
|
||||
{
|
||||
InitMarker();
|
||||
}
|
||||
var a = Locator.GetActiveCamera().WorldToScreenPoint(transform.position);
|
||||
var b = Locator.GetActiveCamera().WorldToScreenPoint(_playerTransform.position);
|
||||
var vector = a - b;
|
||||
vector.z = 0f;
|
||||
var flag = a.z > 0f;
|
||||
if (_canvasMarker.IsVisible() != flag)
|
||||
{
|
||||
_canvasMarker.SetVisibility(flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -163,6 +163,7 @@
|
||||
<Compile Include="OrbSync\QSBOrbSlot.cs" />
|
||||
<Compile Include="Patches\QSBPatchManager.cs" />
|
||||
<Compile Include="Player\Events\ServerSendPlayerStatesEvent.cs" />
|
||||
<Compile Include="Player\PlayerMapMarker.cs" />
|
||||
<Compile Include="Player\PlayerSyncObject.cs" />
|
||||
<Compile Include="QSBInputManager.cs" />
|
||||
<Compile Include="QSBNetworkLobby.cs" />
|
||||
|
@ -48,6 +48,8 @@ namespace QSB.TransformSync
|
||||
var marker = body.gameObject.AddComponent<PlayerHUDMarker>();
|
||||
marker.Init(Player);
|
||||
|
||||
body.gameObject.AddComponent<PlayerMapMarker>().PlayerName = Player.Name;
|
||||
|
||||
Player.Body = body.gameObject;
|
||||
|
||||
return body;
|
||||
|
@ -6,7 +6,7 @@ namespace QSB.Utility
|
||||
{
|
||||
public static class DebugLog
|
||||
{
|
||||
public static void ToConsole(string message, MessageType type = MessageType.Message)
|
||||
public static void ToConsole(string message, MessageType type = MessageType.Message)
|
||||
=> QSBCore.Helper.Console.WriteLine(message, type, GetCallingType(new StackTrace()));
|
||||
|
||||
public static void ToHud(string message)
|
||||
|
Loading…
x
Reference in New Issue
Block a user