custom attach / attach watcher: improve

This commit is contained in:
JohnCorby 2022-02-27 07:19:57 -08:00
parent 2154a22624
commit e6946128ce
2 changed files with 21 additions and 13 deletions

View File

@ -10,7 +10,6 @@ namespace QSB.Player
private void Awake()
{
Harmony.CreateAndPatchAll(typeof(PlayerAttachWatcher));
QSBSceneManager.OnSceneLoaded += (_, _, _) => Current = null;
Destroy(this);
}
@ -18,10 +17,26 @@ namespace QSB.Player
[HarmonyPrefix]
[HarmonyPatch(nameof(PlayerAttachPoint.AttachPlayer))]
private static void AttachPlayer(PlayerAttachPoint __instance) => Current = __instance;
private static void AttachPlayer(PlayerAttachPoint __instance)
{
if (Current != null)
{
Current.DetachPlayer();
}
Current = __instance;
}
[HarmonyPrefix]
[HarmonyPatch(nameof(PlayerAttachPoint.DetachPlayer))]
private static void DetachPlayer() => Current = null;
private static void DetachPlayer(PlayerAttachPoint __instance)
{
if (!__instance.enabled)
{
return;
}
Current = null;
}
}
}
}

View File

@ -1,5 +1,4 @@
using QSB.Player;
using UnityEngine;
using UnityEngine;
namespace QSB.ShipSync
{
@ -39,7 +38,7 @@ namespace QSB.ShipSync
return;
}
var attachedToUs = PlayerAttachWatcher.Current == _playerAttachPoint;
var attachedToUs = _playerAttachPoint.enabled;
_detachPrompt.SetVisibility(attachedToUs);
if (attachedToUs && OWInput.IsNewlyPressed(InputLibrary.cancel, InputMode.Character))
{
@ -49,12 +48,6 @@ namespace QSB.ShipSync
if (!attachedToUs)
{
if (_playerAttachPoint.enabled)
{
// attached to us, then attached to something else
_playerAttachPoint.enabled = false;
}
if (PlayerState.IsAttached())
{
return;