Repository navigation
GlobalEventManager
Ilia Petrov-Komotskii edited this page Sep 24, 2026
·
3 revisions
In-process event bus keyed by the concrete event type. Raising PlayerDied does not call listeners registered for BaseEvent or SenderEvent.
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 for exact typeT. Null event throws.
The listener list is locked while it is copied; callbacks run outside the lock, so a listener may subscribe/unsubscribe without deadlocking. Listeners can still race with each other.
- Exact-type dispatch only. No inheritance matching, no interfaces as event keys unless you raise that exact type.
- Not a networked bus. Same process only.
openupm add com.manefunction.tools-dotnet