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

68 lines
1.7 KiB
C#
Raw Normal View History

2021-04-12 09:37:20 +00:00
using OWML.Common;
2021-04-13 16:25:00 +00:00
using OWML.Utils;
2021-04-16 10:40:13 +00:00
using QSB.Player;
using QSB.Player.TransformSync;
2021-04-12 09:37:20 +00:00
using QSB.Utility;
2021-04-16 10:40:13 +00:00
using QuantumUNET;
2021-04-12 09:37:20 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
2021-04-13 16:25:00 +00:00
using System.Reflection;
2021-04-12 09:37:20 +00:00
using System.Text;
using UnityEngine;
namespace QSB.ShipSync
{
class ShipManager : MonoBehaviour
{
public static ShipManager Instance;
2021-04-13 17:50:15 +00:00
public InteractZone HatchInteractZone;
public HatchController HatchController;
public ShipTractorBeamSwitch ShipTractorBeam;
2021-04-12 09:37:20 +00: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 16:25:00 +00:00
private void Awake()
{
QSBSceneManager.OnUniverseSceneLoaded += OnSceneLoaded;
Instance = this;
}
private void OnSceneLoaded(OWScene scene)
{
if (scene == OWScene.EyeOfTheUniverse)
{
return;
}
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();
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)
{
DebugLog.DebugWrite($"SPAWN SHIP");
QNetworkServer.Spawn(Instantiate(QSBNetworkManager.Instance.ShipPrefab));
}
2021-04-13 16:25:00 +00:00
}
2021-04-12 09:37:20 +00:00
}
}