Links

MEvents

✔

Overview

Events are Scriptable Objects can be used to Broadcast messages so they can be received by a MEventListener in any GameObject. Is a fantastic tool to avoid dependencies like Singletons on your project.

How to Create an Event

You can create a new MEvent using the Create Menu:
Every event can be used multiple times with different values like (Int, Float, String, Bool, Vector2, Vector3, Sprite, Transform, GameObject, Component, IntVar, IDs, FloatVar or Void)
They are widely used all over the Animal Controller to notify changes between different systems.
When an Event is invoked using any of its invoke methods, every active listener will react accordingly. So use them wisely.

Example

Let's create an Event that will notify the UI that the animal is dead.
1 - Prepare a simple scene with a plane, any of the animals player prefabs and the camera prefabs:
2 - Create a new MEvent and call it Animal is dead.
3 - On the Events Group -> State, create a new On Enter, On Exit Event and add the StateID -> Death
4 - Add a new Listener on the OnEnter Event and use the is Animal Death MEvent asset.
5 - Use the Event method Invoke(string). As the value let's set the name of the wolf.
We are using the MEvent.Invoke( String ). Which will be the type that will use later on the Event listener component
6 - Create a Canvas and add a text component. clear the Text value of the text.
7 - Add the EventListener Component and the Value to String Component to the Text GameObject
8 - Add to the Event Listener the Event Is Animal Dead and Select the String Event Type
9. Connect the String Event coming from the Event to the Value to string Dynamic Method.
10 - Add the Prefix "The ". Add the Suffix " is Dead"
11 - Connect the ToString Event with the Text.value dynamic string parameter
​
And that's it!. If the animal dies it will set on the screen, The Wolf is dead.
To make the final test, drag a Death zone into the Scene and move the animal there:
​
The wolf is dead!! not death.. ups
​
​
​
​