78 lines
2.0 KiB
C#
78 lines
2.0 KiB
C#
using Godot;
|
|
using EinSoftworks.Events;
|
|
|
|
namespace Voider;
|
|
|
|
/// <summary>
|
|
/// Autoload singleton that provides access to the ConfigurableEventManager
|
|
/// </summary>
|
|
public partial class EventManager : Node
|
|
{
|
|
private static EventManager _instance;
|
|
public static EventManager Instance => _instance;
|
|
|
|
private ConfigurableEventManager _eventManager;
|
|
|
|
public override void _Ready()
|
|
{
|
|
_instance = this;
|
|
_eventManager = new ConfigurableEventManager();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Raise a game event using the resource's EventName
|
|
/// </summary>
|
|
public void RaiseEvent(GameEventResource eventResource)
|
|
{
|
|
if (eventResource?.EventName != null)
|
|
{
|
|
_eventManager.Raise(eventResource.EventName);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Raise a game event by name
|
|
/// </summary>
|
|
public void RaiseEvent(string eventName)
|
|
{
|
|
_eventManager.Raise(eventName);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Subscribe to a game event using the resource's EventName
|
|
/// </summary>
|
|
public void Subscribe(GameEventResource eventResource, System.Action callback)
|
|
{
|
|
if (eventResource?.EventName != null)
|
|
{
|
|
_eventManager.Subscribe(eventResource.EventName, callback);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Subscribe to a game event by name
|
|
/// </summary>
|
|
public void Subscribe(string eventName, System.Action callback)
|
|
{
|
|
_eventManager.Subscribe(eventName, callback);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Unsubscribe from a game event using the resource's EventName
|
|
/// </summary>
|
|
public void Unsubscribe(GameEventResource eventResource, System.Action callback)
|
|
{
|
|
if (eventResource?.EventName != null)
|
|
{
|
|
_eventManager.Unsubscribe(eventResource.EventName, callback);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Unsubscribe from a game event by name
|
|
/// </summary>
|
|
public void Unsubscribe(string eventName, System.Action callback)
|
|
{
|
|
_eventManager.Unsubscribe(eventName, callback);
|
|
}
|
|
} |