bad-piggies-0.1.3-porting/Assets/Scripts/Assembly-CSharp/EventManager.cs
2024-02-24 22:40:44 -05:00

34 lines
745 B
C#

using System;
public static class EventManager
{
public interface Event
{
}
private class EventTypeManager<T> where T : Event
{
public static OnEvent<T> handler;
}
public delegate void OnEvent<T>(T data) where T : Event;
public static void Send<T>(T data) where T : Event
{
OnEvent<T> handler = EventTypeManager<T>.handler;
if (handler != null)
{
handler(data);
}
}
public static void Connect<T>(OnEvent<T> handler) where T : Event
{
EventTypeManager<T>.handler = (OnEvent<T>)Delegate.Combine(EventTypeManager<T>.handler, handler);
}
public static void Disconnect<T>(OnEvent<T> handler) where T : Event
{
EventTypeManager<T>.handler = (OnEvent<T>)Delegate.Remove(EventTypeManager<T>.handler, handler);
}
}