diff --git a/QSB/DeathSync/Events/PlayerDeathEvent.cs b/QSB/DeathSync/Events/PlayerDeathEvent.cs index 00234ade..8767faf6 100644 --- a/QSB/DeathSync/Events/PlayerDeathEvent.cs +++ b/QSB/DeathSync/Events/PlayerDeathEvent.cs @@ -1,6 +1,7 @@ using QSB.ClientServerStateSync; using QSB.Events; using QSB.Player; +using QSB.RespawnSync; using QSB.Utility; namespace QSB.DeathSync.Events diff --git a/QSB/DeathSync/RespawnOnDeath.cs b/QSB/DeathSync/RespawnOnDeath.cs index 3de0b193..49aeb1a7 100644 --- a/QSB/DeathSync/RespawnOnDeath.cs +++ b/QSB/DeathSync/RespawnOnDeath.cs @@ -7,6 +7,7 @@ using QSB.WorldSync; using QSB.Utility; using System.Linq; using UnityEngine; +using QSB.RespawnSync; namespace QSB.DeathSync { diff --git a/QSB/Events/QSBEventManager.cs b/QSB/Events/QSBEventManager.cs index 979e9c56..e2e5c7a8 100644 --- a/QSB/Events/QSBEventManager.cs +++ b/QSB/Events/QSBEventManager.cs @@ -30,6 +30,7 @@ using QSB.Anglerfish.Events; using QSB.Utility; using QSB.Utility.Events; using System.Collections.Generic; +using QSB.RespawnSync.Events; namespace QSB.Events { diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index b8488517..fce23679 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -88,13 +88,14 @@ - + - - + + + diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index 358ee1b7..22fab8b7 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -4,7 +4,6 @@ using OWML.ModHelper.Input; using QSB.Animation.NPC; using QSB.CampfireSync; using QSB.ConversationSync; -using QSB.DeathSync; using QSB.EchoesOfTheEye.AirlockSync; using QSB.EchoesOfTheEye.LightSensorSync; using QSB.ElevatorSync; @@ -32,6 +31,7 @@ using QuantumUNET; using QuantumUNET.Components; using System.Linq; using UnityEngine; +using QSB.RespawnSync; /* Copyright (C) 2020 - 2021 diff --git a/QSB/DeathSync/Events/PlayerRespawnEvent.cs b/QSB/RespawnSync/Events/PlayerRespawnEvent.cs similarity index 97% rename from QSB/DeathSync/Events/PlayerRespawnEvent.cs rename to QSB/RespawnSync/Events/PlayerRespawnEvent.cs index 83e7e44b..51af5b16 100644 --- a/QSB/DeathSync/Events/PlayerRespawnEvent.cs +++ b/QSB/RespawnSync/Events/PlayerRespawnEvent.cs @@ -3,7 +3,7 @@ using QSB.Events; using QSB.Messaging; using QSB.Player; -namespace QSB.DeathSync.Events +namespace QSB.RespawnSync.Events { internal class PlayerRespawnEvent : QSBEvent { diff --git a/QSB/RespawnSync/RespawnHUDMarker.cs b/QSB/RespawnSync/RespawnHUDMarker.cs new file mode 100644 index 00000000..472234f8 --- /dev/null +++ b/QSB/RespawnSync/RespawnHUDMarker.cs @@ -0,0 +1,73 @@ +using QSB.Player; +using QSB.Utility; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace QSB.RespawnSync +{ + public class RespawnHUDMarker : HUDDistanceMarker + { + private bool _isReady; + + public override void InitCanvasMarker() + { + DebugLog.DebugWrite($"InitCanvasMarker"); + + _markerRadius = 2f; + + _markerTarget = new GameObject().transform; + _markerTarget.parent = transform; + + _markerTarget.localPosition = Vector3.up * 0.25f; + } + + private void Update() + { + if (!_isReady) + { + return; + } + + if (_canvasMarker != null) + { + var isVisible = _canvasMarker.IsVisible(); + + if (RespawnManager.Instance.RespawnNeeded != isVisible) + { + DebugLog.DebugWrite($"set visibility to {isVisible}"); + _canvasMarker.SetVisibility(RespawnManager.Instance.RespawnNeeded); + } + } + } + + public void Initialize() + { + DebugLog.DebugWrite($"initialize"); + _markerLabel = "RESPAWN PLAYER"; + _isReady = true; + + base.InitCanvasMarker(); + } + + public void Remove() + { + _isReady = false; + // do N O T destroy the parent - it completely breaks the ENTIRE GAME + if (_canvasMarker != null) + { + _canvasMarker.DestroyMarker(); + } + + if (_markerTarget != null) + { + Destroy(_markerTarget.gameObject); + } + + Destroy(this); + } + } +} diff --git a/QSB/DeathSync/RespawnManager.cs b/QSB/RespawnSync/RespawnManager.cs similarity index 97% rename from QSB/DeathSync/RespawnManager.cs rename to QSB/RespawnSync/RespawnManager.cs index 438a8ecc..b520980e 100644 --- a/QSB/DeathSync/RespawnManager.cs +++ b/QSB/RespawnSync/RespawnManager.cs @@ -8,7 +8,7 @@ using System.Linq; using UnityEngine; using UnityEngine.Networking; -namespace QSB.DeathSync +namespace QSB.RespawnSync { internal class RespawnManager : MonoBehaviour { @@ -90,6 +90,9 @@ namespace QSB.DeathSync multiInteract._interactRange = 1.5f; _qsbRecoveryPoint.AddComponent(); + + var marker = _qsbRecoveryPoint.AddComponent(); + marker.Initialize(); } _qsbRecoveryPoint.SetActive(true); diff --git a/QSB/DeathSync/ShipRecoveryPoint.cs b/QSB/RespawnSync/ShipRecoveryPoint.cs similarity index 99% rename from QSB/DeathSync/ShipRecoveryPoint.cs rename to QSB/RespawnSync/ShipRecoveryPoint.cs index dc5203c6..64c7417e 100644 --- a/QSB/DeathSync/ShipRecoveryPoint.cs +++ b/QSB/RespawnSync/ShipRecoveryPoint.cs @@ -1,7 +1,7 @@ using QSB.Utility; using UnityEngine; -namespace QSB.DeathSync +namespace QSB.RespawnSync { internal class ShipRecoveryPoint : MonoBehaviour {