Inventory Engine  v4.0
Static Public Member Functions | List of all members
MoreMountains.Tools.MMEventManager Class Reference

This class handles event management, and can be used to broadcast events throughout the game, to tell one class (or many) that something's happened. More...

Static Public Member Functions

static void AddListener< MMEvent > (MMEventListener< MMEvent > listener)
 Adds a new subscriber to a certain event. More...
 
static void RemoveListener< MMEvent > (MMEventListener< MMEvent > listener)
 Removes a subscriber from a certain event. More...
 
static void TriggerEvent< MMEvent > (MMEvent newEvent)
 Triggers an event. More...
 

Detailed Description

This class handles event management, and can be used to broadcast events throughout the game, to tell one class (or many) that something's happened.

Events are structs, you can define any kind of events you want. This manager comes with MMGameEvents, which are basically just made of a string, but you can work with more complex ones if you want.

To trigger a new event, from anywhere, do YOUR_EVENT.Trigger(YOUR_PARAMETERS) So MMGameEvent.Trigger("Save"); for example will trigger a Save MMGameEvent

you can also call MMEventManager.TriggerEvent(YOUR_EVENT); For example : MMEventManager.TriggerEvent(new MMGameEvent("GameStart")); will broadcast an MMGameEvent named GameStart to all listeners.

To start listening to an event from any class, there are 3 things you must do :

1 - tell that your class implements the MMEventListener interface for that kind of event. For example: public class GUIManager : Singleton<GUIManager>, MMEventListener<MMGameEvent> You can have more than one of these (one per event type).

2 - On Enable and Disable, respectively start and stop listening to the event : void OnEnable() { this.MMEventStartListening<MMGameEvent>(); } void OnDisable() { this.MMEventStopListening<MMGameEvent>(); }

3 - Implement the MMEventListener interface for that event. For example : public void OnMMEvent(MMGameEvent gameEvent) { if (gameEvent.EventName == "GameOver") { // DO SOMETHING } } will catch all events of type MMGameEvent emitted from anywhere in the game, and do something if it's named GameOver

Member Function Documentation

◆ AddListener< MMEvent >()

static void MoreMountains.Tools.MMEventManager.AddListener< MMEvent > ( MMEventListener< MMEvent >  listener)
static

Adds a new subscriber to a certain event.

Parameters
listenerlistener.
Template Parameters
MMEventThe event type.
Type Constraints
MMEvent :struct 

◆ RemoveListener< MMEvent >()

static void MoreMountains.Tools.MMEventManager.RemoveListener< MMEvent > ( MMEventListener< MMEvent >  listener)
static

Removes a subscriber from a certain event.

Parameters
listenerlistener.
Template Parameters
MMEventThe event type.
Type Constraints
MMEvent :struct 

◆ TriggerEvent< MMEvent >()

static void MoreMountains.Tools.MMEventManager.TriggerEvent< MMEvent > ( MMEvent  newEvent)
static

Triggers an event.

All instances that are subscribed to it will receive it (and will potentially act on it).

Parameters
newEventThe event to trigger.
Template Parameters
MMEventThe 1st type parameter.
Type Constraints
MMEvent :struct 

The documentation for this class was generated from the following file: