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

64 lines
1.8 KiB
C#
Raw Normal View History

2021-04-12 09:37:20 +00:00
using OWML.Common;
using QSB.Player;
using QSB.Player.TransformSync;
using QSB.ShipSync.TransformSync;
2021-04-12 09:37:20 +00:00
using QSB.Utility;
using QSB.WorldSync;
2021-04-16 10:40:13 +00:00
using QuantumUNET;
2021-04-12 09:37:20 +00:00
using System.Linq;
using UnityEngine;
namespace QSB.ShipSync
{
internal class ShipManager : WorldObjectManager
2021-04-12 09:37:20 +00:00
{
public static ShipManager Instance;
2021-04-13 17:50:15 +00:00
public InteractZone HatchInteractZone;
public HatchController HatchController;
public ShipTractorBeamSwitch ShipTractorBeam;
public ShipCockpitController CockpitController;
public bool HasAuthority
=> ShipTransformSync.LocalInstance.HasAuthority;
2021-04-12 09:37:20 +00:00
public uint CurrentFlyer
{
get => _currentFlyer;
set
{
if (_currentFlyer != uint.MaxValue && value != uint.MaxValue)
{
DebugLog.ToConsole($"Warning - Trying to set current flyer while someone is still flying? Current:{_currentFlyer}, New:{value}", MessageType.Warning);
}
_currentFlyer = value;
}
}
2021-04-13 16:25:00 +00:00
private uint _currentFlyer = uint.MaxValue;
2021-04-13 16:25:00 +00:00
public void Start()
=> Instance = this;
2021-04-13 20:09:26 +00:00
protected override void RebuildWorldObjects(OWScene scene)
{
2021-04-13 20:09:26 +00:00
var shipTransform = GameObject.Find("Ship_Body");
HatchController = shipTransform.GetComponentInChildren<HatchController>();
HatchInteractZone = HatchController.GetComponent<InteractZone>();
ShipTractorBeam = Resources.FindObjectsOfTypeAll<ShipTractorBeamSwitch>().First();
CockpitController = Resources.FindObjectsOfTypeAll<ShipCockpitController>().First();
2021-04-13 16:25:00 +00:00
2021-04-13 17:50:15 +00:00
var sphereShape = HatchController.GetComponent<SphereShape>();
2021-04-13 16:25:00 +00:00
sphereShape.radius = 2.5f;
sphereShape.center = new Vector3(0, 0, 1);
2021-04-16 10:40:13 +00:00
if (QSBCore.IsServer)
{
if (ShipTransformSync.LocalInstance != null)
{
QNetworkServer.Destroy(ShipTransformSync.LocalInstance.gameObject);
}
2021-04-16 10:40:13 +00:00
QNetworkServer.Spawn(Instantiate(QSBNetworkManager.Instance.ShipPrefab));
}
2021-04-13 16:25:00 +00:00
}
2021-04-12 09:37:20 +00:00
}
}