93 lines
3.0 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-18 12:33:07 +00:00
using System.Linq;
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;
2021-01-18 12:33:07 +00:00
public QuantumShrine Shrine;
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>();
2021-01-26 14:07:17 +00:00
if (scene == OWScene.SolarSystem)
{
Shrine = Resources.FindObjectsOfTypeAll<QuantumShrine>().First();
}
2020-12-22 21:39:53 +00:00
}
2021-01-26 14:07:17 +00:00
public void OnRenderObject()
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-18 12:33:07 +00:00
2021-01-26 14:07:17 +00:00
if (Shrine != null)
{
Popcron.Gizmos.Sphere(Shrine.transform.position, 10f, Color.magenta);
}
}
public void OnGUI()
{
if (!QSBCore.HasWokenUp || !QSBCore.DebugMode)
{
return;
}
2021-01-18 12:33:07 +00:00
GUI.Label(new Rect(220, 10, 200f, 20f), $"QM Visible : {Locator.GetQuantumMoon().IsVisible()}");
2021-01-05 15:56:14 +00:00
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-18 12:33:07 +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;
}
offset = 10f;
GUI.Label(new Rect(440, offset, 200f, 20f), $"Players in QM :");
offset += 30f;
foreach (var player in QSBPlayerManager.PlayerList.Where(x => x.IsInMoon))
{
GUI.Label(new Rect(440, offset, 200f, 20f), $"- {player.PlayerId}");
offset += 30f;
}
GUI.Label(new Rect(440, offset, 200f, 20f), $"Players in Shrine :");
offset += 30f;
foreach (var player in QSBPlayerManager.PlayerList.Where(x => x.IsInShrine))
{
GUI.Label(new Rect(440, offset, 200f, 20f), $"- {player.PlayerId}");
2021-01-05 15:56:14 +00:00
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
}