smart-interactive-display/Assets/graphQl-client/Scripts/EventCallbacks/Event.cs

37 lines
1010 B
C#
Raw Normal View History

2024-05-21 04:32:10 -07:00
using System;
using UnityEngine;
namespace GraphQlClient.EventCallbacks
{
public abstract class Event<T> where T : Event<T> {
/*
* The base Event,
* might have some generic text
* for doing Debug.Log?
*/
public string Description;
private bool hasFired;
public delegate void EventListener(T info);
private static event EventListener listeners;
public static void RegisterListener(EventListener listener) {
listeners += listener;
}
public static void UnregisterListener(EventListener listener) {
listeners -= listener;
}
public void FireEvent() {
if (hasFired) {
throw new Exception("This event has already fired, to prevent infinite loops you can't refire an event");
}
hasFired = true;
if (listeners != null) {
listeners(this as T);
}
}
}
}