quantum-space-buddies/QSB/GeyserSync/GeyserManager.cs

44 lines
1.0 KiB
C#
Raw Normal View History

2020-11-04 20:01:28 +00:00
using QSB.Patches;
using QSB.WorldSync;
using UnityEngine;
2020-08-13 17:25:12 +00:00
namespace QSB.GeyserSync
{
2020-12-02 21:23:01 +00:00
public class GeyserManager : MonoBehaviour
{
public static GeyserManager Instance { get; private set; }
2020-08-13 17:25:12 +00:00
2020-12-02 21:23:01 +00:00
private void Awake()
{
Instance = this;
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
QSBPatchManager.OnPatchType += OnPatchType;
}
2020-08-13 17:25:12 +00:00
2020-12-02 21:23:01 +00:00
private void OnDestroy()
{
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
QSBPatchManager.OnPatchType -= OnPatchType;
}
2020-11-25 09:54:52 +00:00
2020-12-02 21:23:01 +00:00
private void OnSceneLoaded(OWScene scene, bool isInUniverse)
{
var geyserControllers = Resources.FindObjectsOfTypeAll<GeyserController>();
for (var id = 0; id < geyserControllers.Length; id++)
{
var qsbGeyser = WorldRegistry.GetObject<QSBGeyser>(id) ?? new QSBGeyser();
qsbGeyser.Init(geyserControllers[id], id);
WorldRegistry.AddObject(qsbGeyser);
}
}
2020-08-20 18:31:10 +00:00
2020-12-02 21:23:01 +00:00
public void OnPatchType(QSBPatchTypes type)
{
if (type != QSBPatchTypes.OnNonServerClientConnect)
{
return;
}
QSB.Helper.HarmonyHelper.EmptyMethod<GeyserController>("Update");
}
}
2020-08-13 17:25:12 +00:00
}