Refactor event management: remove old EventManager and EventExample scripts, add new Core/EventManager as singleton
This commit is contained in:
78
Scripts/Core/EventManager.cs
Normal file
78
Scripts/Core/EventManager.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
1
Scripts/Core/EventManager.cs.uid
Normal file
1
Scripts/Core/EventManager.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://yt5e67nfdc6y
|
||||
Reference in New Issue
Block a user