quantum-space-buddies/QSB/QuantumSync/QuantumManager.cs

57 lines
2.1 KiB
C#
Raw Normal View History

2021-01-03 16:09:58 +00:00
using OWML.Utils;
2021-01-05 15:56:14 +00:00
using QSB.Player;
2021-01-03 16:09:58 +00:00
using QSB.QuantumSync.WorldObjects;
using QSB.WorldSync;
2020-12-22 21:39:53 +00:00
using System.Collections.Generic;
2021-01-05 15:56:14 +00:00
using System.Reflection;
2020-12-22 21:39:53 +00:00
using UnityEngine;
namespace QSB.QuantumSync
{
internal class QuantumManager : MonoBehaviour
{
public static QuantumManager Instance { get; private set; }
private List<SocketedQuantumObject> _socketedQuantumObjects;
2020-12-23 22:43:05 +00:00
private List<MultiStateQuantumObject> _multiStateQuantumObjects;
2020-12-22 21:39:53 +00:00
private List<QuantumSocket> _quantumSockets;
2021-01-01 10:17:35 +00:00
private List<QuantumShuffleObject> _quantumShuffleObjects;
2020-12-22 21:39:53 +00:00
public void Awake()
{
Instance = this;
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
}
2020-12-23 22:43:05 +00:00
public void OnDestroy() => QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
2020-12-22 21:39:53 +00:00
private void OnSceneLoaded(OWScene scene, bool isInUniverse)
{
_socketedQuantumObjects = QSBWorldSync.Init<QSBSocketedQuantumObject, SocketedQuantumObject>();
_multiStateQuantumObjects = QSBWorldSync.Init<QSBMultiStateQuantumObject, MultiStateQuantumObject>();
2020-12-24 15:57:25 +00:00
_quantumSockets = QSBWorldSync.Init<QSBQuantumSocket, QuantumSocket>();
2021-01-01 10:17:35 +00:00
_quantumShuffleObjects = QSBWorldSync.Init<QSBQuantumShuffleObject, QuantumShuffleObject>();
2020-12-22 21:39:53 +00:00
}
2021-01-05 15:56:14 +00:00
private void OnGUI()
2021-01-03 16:09:58 +00:00
{
2021-01-05 15:56:14 +00:00
if (!QSBCore.HasWokenUp || !QSBCore.DebugMode)
2021-01-03 16:09:58 +00:00
{
return;
}
2021-01-05 15:56:14 +00:00
GUI.Label(new Rect(220, 10, 200f, 20f), $"QM Visible:{Locator.GetQuantumMoon().IsVisible()}");
var offset = 40f;
var tracker = Locator.GetQuantumMoon().GetValue<ShapeVisibilityTracker>("_visibilityTracker");
foreach (var camera in QSBPlayerManager.GetPlayerCameras())
2021-01-03 16:09:58 +00:00
{
2021-01-05 15:56:14 +00:00
GUI.Label(new Rect(220, offset, 200f, 20f), $"{camera.name} : {tracker.GetType().GetMethod("IsInFrustum", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(tracker, new object[] { camera.GetFrustumPlanes() })}");
offset += 30f;
2021-01-03 16:09:58 +00:00
}
}
2020-12-22 21:39:53 +00:00
public int GetId(SocketedQuantumObject obj) => _socketedQuantumObjects.IndexOf(obj);
2020-12-23 22:43:05 +00:00
public int GetId(MultiStateQuantumObject obj) => _multiStateQuantumObjects.IndexOf(obj);
2020-12-22 21:39:53 +00:00
public int GetId(QuantumSocket obj) => _quantumSockets.IndexOf(obj);
2021-01-01 10:17:35 +00:00
public int GetId(QuantumShuffleObject obj) => _quantumShuffleObjects.IndexOf(obj);
2020-12-22 21:39:53 +00:00
}
2020-12-23 10:43:13 +00:00
}