quantum-space-buddies/QSB/WorldRegistry.cs

40 lines
1.2 KiB
C#
Raw Normal View History

2020-08-13 14:32:58 +01:00
using QSB.Events;
using QSB.Utility;
using QSB.WorldSync;
2020-08-13 10:16:56 +01:00
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
2020-08-13 14:32:58 +01:00
using UnityEngine.Networking;
2020-08-13 10:16:56 +01:00
namespace QSB
{
public static class WorldRegistry
{
2020-08-13 14:32:58 +01:00
public static List<GeyserController> GeyserControllers = new List<GeyserController>();
2020-08-13 10:16:56 +01:00
2020-08-13 14:32:58 +01:00
public static void GenerateComponentList()
2020-08-13 10:16:56 +01:00
{
2020-08-13 14:32:58 +01:00
GeyserControllers = Resources.FindObjectsOfTypeAll<GeyserController>().ToList();
foreach (var component in GeyserControllers)
2020-08-13 10:16:56 +01:00
{
2020-08-13 14:32:58 +01:00
if (NetworkServer.active)
{
component.OnGeyserActivateEvent += () => GlobalMessenger<GeyserController, bool>.FireEvent(EventNames.QSBGeyserState, component, true);
component.OnGeyserDeactivateEvent += () => GlobalMessenger<GeyserController, bool>.FireEvent(EventNames.QSBGeyserState, component, false);
}
2020-08-13 10:16:56 +01:00
}
}
2020-08-13 14:32:58 +01:00
public static int GetObjectID(SyncObjects type, object component)
{
switch (type)
{
case SyncObjects.Geysers:
return GeyserControllers.FindIndex(x => x == component);
}
return 0;
}
2020-08-13 10:16:56 +01:00
}
}