Events Manager
Presented via IEventsManager interface, this system registers, listens and triggers various events.
To use this system, inject IEventsManager interface into your class, as shown below:
[Inject] private IEventsManager eventsManager;Available methods
void RegisterListener(string eventType, UnityAction listener)Registers event listener without parameters.
Examples:
eventsManager.RegisterListener("PlayerDeath", OnPlayerDeath);
eventsManager.RegisterListener("GameWin", () => { Debug.Log("Victory!"); });void RegisterListener<T>(string eventType, UnityAction<T> listener)Registers event listener with single parameter of any type.
Examples:
eventsManager.RegisterListener<int>("PlayerDamageGot", OnPlayerDamageGot);
eventsManager.RegisterListener("GameWin", (score) => { Debug.Log($"Victory! Score: {score}"); });void RegisterListener<T1, T2>(string eventType, UnityAction<T1, T2> listener)Registers event listener with 2 parameters of any types.
Example:
eventsManager.RegisterListener<int, string>("PlayerDamageGot", (damage, enemyName) => { Debug.Log($"Damage got: {damage} from {enemyName}"); });void UnregisterListener(string eventType, UnityAction listener)Unregisters event listener without parameters.
Example:
eventsManager.UnregisterListener("PlayerDeath", OnPlayerDeath);void UnregisterListener<T>(string eventType, UnityAction<T> listener)Unregisters event listener with 1 parameter of any type.
Example:
eventsManager.UnregisterListener<int>("PlayerDamageGot", OnPlayerDamageGot);void UnregisterListener<T1, T2>(string eventType, UnityAction<T1, T2> listener)Unregisters event listener with 2 parameters of any types.
Example:
eventsManager.UnregisterListener<int, string>("PlayerDamageGot", OnPlayerDamageGot);void TriggerEvent(string eventType)Triggers event without parameters.
Example:
eventsManager.TriggerEvent("PlayerDeath");void TriggerEvent<T>(string eventType, T value)Triggers event with 1 parameter of any type.
Example:
eventsManager.TriggerEvent<int>("GameWin", score);void TriggerEvent<T1, T2>(string eventType, T1 value1, T2 value2)Triggers event with 2 parameters of any types.
Example:
eventsManager.TriggerEvent<int, string>("OnDamageGot", damage, enemyName);Last updated