quantum-space-buddies/QSB/ShipSync/ShipCustomAttach.cs

81 lines
2.4 KiB
C#
Raw Normal View History

2022-02-05 11:15:54 +00:00
using QSB.Player;
using UnityEngine;
2022-02-01 00:33:11 +00:00
namespace QSB.ShipSync
{
public class ShipCustomAttach : MonoBehaviour
{
2022-02-01 01:26:35 +00:00
private static readonly ScreenPrompt _attachPrompt = new(InputLibrary.interactSecondary, InputLibrary.interact,
"Attach to ship" + " <CMD>", ScreenPrompt.MultiCommandType.HOLD_ONE_AND_PRESS_2ND);
private static readonly ScreenPrompt _detachPrompt = new(InputLibrary.cancel, "Detach from ship" + " <CMD>");
2022-02-01 00:33:11 +00:00
private PlayerAttachPoint _playerAttachPoint;
private void Awake()
{
2022-02-01 01:26:35 +00:00
Locator.GetPromptManager().AddScreenPrompt(_attachPrompt, PromptPosition.UpperRight);
Locator.GetPromptManager().AddScreenPrompt(_detachPrompt, PromptPosition.UpperRight);
2022-02-01 00:33:11 +00:00
_playerAttachPoint = gameObject.AddComponent<PlayerAttachPoint>();
_playerAttachPoint._lockPlayerTurning = false;
_playerAttachPoint._matchRotation = false;
_playerAttachPoint._centerCamera = false;
}
2022-02-01 01:26:35 +00:00
private void OnDestroy()
{
if (Locator.GetPromptManager())
{
Locator.GetPromptManager().RemoveScreenPrompt(_attachPrompt, PromptPosition.UpperRight);
Locator.GetPromptManager().RemoveScreenPrompt(_detachPrompt, PromptPosition.UpperRight);
}
}
2022-02-01 00:33:11 +00:00
private void Update()
{
2022-02-01 01:26:35 +00:00
_attachPrompt.SetVisibility(false);
_detachPrompt.SetVisibility(false);
2022-02-01 00:33:11 +00:00
if (!PlayerState.IsInsideShip())
{
return;
}
2022-02-05 11:15:54 +00:00
var attachedToUs = PlayerAttachWatcher.Current == _playerAttachPoint;
2022-02-08 04:48:17 +00:00
_detachPrompt.SetVisibility(attachedToUs);
if (attachedToUs && OWInput.IsNewlyPressed(InputLibrary.cancel, InputMode.Character))
{
_playerAttachPoint.DetachPlayer();
ShipManager.Instance.CockpitController._shipAudioController.PlayUnbuckle();
}
if (!attachedToUs)
2022-02-01 00:33:11 +00:00
{
if (_playerAttachPoint.enabled)
{
// attached to us, then attached to something else
_playerAttachPoint.enabled = false;
}
if (PlayerState.IsAttached())
{
return;
}
if (Locator.GetPlayerController() && !Locator.GetPlayerController().IsGrounded())
{
return;
}
2022-02-01 00:33:11 +00:00
}
2022-02-01 01:26:35 +00:00
_attachPrompt.SetVisibility(!attachedToUs);
if (!attachedToUs &&
OWInput.IsPressed(InputLibrary.interactSecondary, InputMode.Character) &&
OWInput.IsNewlyPressed(InputLibrary.interact, InputMode.Character))
{
transform.position = Locator.GetPlayerTransform().position;
_playerAttachPoint.AttachPlayer();
2022-02-04 22:45:43 +00:00
ShipManager.Instance.CockpitController._shipAudioController.PlayBuckle();
2022-02-01 01:26:35 +00:00
}
2022-02-01 00:33:11 +00:00
}
}
}