42 lines
1.0 KiB
C#
Raw Normal View History

2020-08-13 19:25:12 +02:00
using QSB.Events;
using QSB.WorldSync;
using UnityEngine.Networking;
namespace QSB.GeyserSync
{
public class QSBGeyser : WorldObject
{
private GeyserController _geyserController;
2020-08-13 20:43:47 +02:00
public void Init(GeyserController geyserController, int id)
2020-08-13 19:25:12 +02:00
{
2020-08-13 20:43:47 +02:00
Id = id;
2020-08-13 19:25:12 +02:00
WorldRegistry.WorldObjects.Add(this);
_geyserController = geyserController;
geyserController.OnGeyserActivateEvent += () => HandleEvent(true);
geyserController.OnGeyserDeactivateEvent += () => HandleEvent(false);
}
private void HandleEvent(bool state)
{
if (NetworkServer.active)
{
2020-08-13 20:43:47 +02:00
GlobalMessenger<int, bool>.FireEvent(EventNames.QSBGeyserState, Id, state);
2020-08-13 19:25:12 +02:00
}
}
public void SetState(bool state)
{
if (state)
{
_geyserController.ActivateGeyser();
}
else
{
_geyserController.DeactivateGeyser();
}
}
}
}