61 lines
1.5 KiB
C#
Raw Normal View History

2021-04-12 10:37:20 +01:00
using OWML.Common;
using QSB.Utility;
2021-04-16 11:40:13 +01:00
using QuantumUNET;
2021-04-12 10:37:20 +01:00
using System.Linq;
using UnityEngine;
namespace QSB.ShipSync
{
2021-05-15 21:31:29 +01:00
internal class ShipManager : MonoBehaviour
2021-04-12 10:37:20 +01:00
{
public static ShipManager Instance;
2021-04-13 18:50:15 +01:00
public InteractZone HatchInteractZone;
public HatchController HatchController;
public ShipTractorBeamSwitch ShipTractorBeam;
2021-04-12 10:37:20 +01:00
private uint _currentFlyer = uint.MaxValue;
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 17:25:00 +01:00
private void Awake()
{
QSBSceneManager.OnUniverseSceneLoaded += OnSceneLoaded;
Instance = this;
}
private void OnSceneLoaded(OWScene scene)
{
if (scene == OWScene.EyeOfTheUniverse)
{
return;
}
2021-04-13 21:09:26 +01:00
var shipTransform = GameObject.Find("Ship_Body");
HatchController = shipTransform.GetComponentInChildren<HatchController>();
HatchInteractZone = HatchController.GetComponent<InteractZone>();
ShipTractorBeam = Resources.FindObjectsOfTypeAll<ShipTractorBeamSwitch>().First();
2021-04-13 17:25:00 +01:00
2021-04-13 18:50:15 +01:00
var sphereShape = HatchController.GetComponent<SphereShape>();
2021-04-13 17:25:00 +01:00
sphereShape.radius = 2.5f;
sphereShape.center = new Vector3(0, 0, 1);
2021-04-16 11:40:13 +01:00
if (QSBCore.IsServer)
{
DebugLog.DebugWrite($"SPAWN SHIP");
QNetworkServer.Spawn(Instantiate(QSBNetworkManager.Instance.ShipPrefab));
}
2021-04-13 17:25:00 +01:00
}
2021-04-12 10:37:20 +01:00
}
}