mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-01 03:32:38 +00:00
custom ship attach
This commit is contained in:
parent
c49828c13c
commit
2f60039ca6
56
QSB/ShipSync/ShipCustomAttach.cs
Normal file
56
QSB/ShipSync/ShipCustomAttach.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.ShipSync
|
||||
{
|
||||
public class ShipCustomAttach : MonoBehaviour
|
||||
{
|
||||
private const string ATTACH_TEXT = "Attach to ship";
|
||||
private const string DETACH_TEXT = "Detach from ship";
|
||||
private static readonly ScreenPrompt _prompt = new(InputLibrary.interactSecondary, ATTACH_TEXT + " <CMD>");
|
||||
private PlayerAttachPoint _playerAttachPoint;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Locator.GetPromptManager().AddScreenPrompt(_prompt, PromptPosition.UpperRight);
|
||||
|
||||
_playerAttachPoint = gameObject.AddComponent<PlayerAttachPoint>();
|
||||
_playerAttachPoint._lockPlayerTurning = false;
|
||||
_playerAttachPoint._matchRotation = false;
|
||||
_playerAttachPoint._centerCamera = false;
|
||||
}
|
||||
|
||||
private void OnDestroy() =>
|
||||
Locator.GetPromptManager().RemoveScreenPrompt(_prompt, PromptPosition.UpperRight);
|
||||
|
||||
private void Update()
|
||||
{
|
||||
_prompt.SetVisibility(false);
|
||||
if (!PlayerState.IsInsideShip())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var attachedToUs = _playerAttachPoint.enabled;
|
||||
if (PlayerState.IsAttached() && !attachedToUs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_prompt.SetVisibility(true);
|
||||
if (OWInput.IsNewlyPressed(InputLibrary.interactSecondary, InputMode.Character))
|
||||
{
|
||||
if (!attachedToUs)
|
||||
{
|
||||
transform.position = Locator.GetPlayerTransform().position;
|
||||
_playerAttachPoint.AttachPlayer();
|
||||
_prompt.SetText(DETACH_TEXT + " <CMD>");
|
||||
}
|
||||
else
|
||||
{
|
||||
_playerAttachPoint.DetachPlayer();
|
||||
_prompt.SetText(ATTACH_TEXT + " <CMD>");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
|
||||
@ -24,6 +25,7 @@ namespace QSB.ShipSync
|
||||
public ShipTractorBeamSwitch ShipTractorBeam;
|
||||
public ShipCockpitController CockpitController;
|
||||
public ShipElectricalComponent ShipElectricalComponent;
|
||||
private GameObject _shipCustomAttach;
|
||||
public uint CurrentFlyer
|
||||
{
|
||||
get => _currentFlyer;
|
||||
@ -47,14 +49,14 @@ namespace QSB.ShipSync
|
||||
|
||||
public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct)
|
||||
{
|
||||
var shipTransform = GameObject.Find("Ship_Body");
|
||||
if (shipTransform == null)
|
||||
var shipBody = Locator.GetShipBody();
|
||||
if (shipBody == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - Couldn't find ship!", MessageType.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
HatchController = shipTransform.GetComponentInChildren<HatchController>();
|
||||
HatchController = shipBody.GetComponentInChildren<HatchController>();
|
||||
if (HatchController == null)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - Couldn't find hatch controller!", MessageType.Error);
|
||||
@ -93,8 +95,14 @@ namespace QSB.ShipSync
|
||||
|
||||
QSBWorldSync.Init<QSBShipComponent, ShipComponent>();
|
||||
QSBWorldSync.Init<QSBShipHull, ShipHull>();
|
||||
|
||||
_shipCustomAttach = new GameObject(nameof(ShipCustomAttach));
|
||||
_shipCustomAttach.transform.SetParent(shipBody.transform, false);
|
||||
_shipCustomAttach.AddComponent<ShipCustomAttach>();
|
||||
}
|
||||
|
||||
public override void UnbuildWorldObjects() => Destroy(_shipCustomAttach);
|
||||
|
||||
public void AddPlayerToShip(PlayerInfo player)
|
||||
{
|
||||
DebugLog.DebugWrite($"{player.PlayerId} enter ship.");
|
||||
|
Loading…
Reference in New Issue
Block a user