Repository navigation
GlobalEventManager
Ilia Petrov-Komotskii edited this page Sep 29, 2026
·
3 revisions
In-process event bus keyed by event type. Raising an event also calls listeners of each base type. Matching listeners run in the order they were subscribed. A base instance does not call listeners of a more derived type.
GlobalEventManager is itself a ManeSingleton. Access it through GlobalEventManager.Instance.
using Mane.DotNet;
public sealed class PlayerDied : SenderEvent<Player>
{
public PlayerDied(Player player) : base(player) { }
}
void OnEnable()
{
GlobalEventManager.Instance.AddListener<PlayerDied>(OnPlayerDied);
}
void OnDisable()
{
GlobalEventManager.Instance.RemoveListener<PlayerDied>(OnPlayerDied);
}
void OnPlayerDied(PlayerDied e)
{
Debug.Log($"{e.Sender.name} died");
}
void Kill(Player player)
{
GlobalEventManager.Instance.RaiseEvent(new PlayerDied(player));
}| Type | Role |
|---|---|
BaseEvent |
Marker base. Every event must derive from it. |
SenderEvent |
Adds an untyped Sender object (may be null). |
SenderEvent<T> |
Typed Sender (T : class). |
EventDelegate<T> |
void(T e) listener signature. |
-
AddListener<T>(EventDelegate<T>)— subscribe. The same delegate is not added twice. Null throws. -
RemoveListener<T>(EventDelegate<T>)— unsubscribe. Null is a no-op. -
RaiseEvent<T>(T e)— invoke listeners of the runtime type ofeand of each base type, in subscription order. Null event throws.
The listener lists are locked while they are copied; callbacks run outside the lock, so a listener may subscribe/unsubscribe without deadlocking. Listeners can still race with each other.
openupm add com.manefunction.tools-dotnet