This Event Manager is made special for small-medium Unity games where simplicity is preferred over performance.
Usage:
- Copy the file in your Unity project;
- Add the EventManager.cs to a GameObject in your Scene (GameManager or EventManager preferred);
- Declare your events in EventName enum;
- You can Subscribe and Unsubscribe really easy by using StartListening and StopListening methods;
- Use TriggerEvent method to trigger the event you wish for;
Advantages:
- Easy to add in a project;
- Easy to use;
- Using dynamic keyword you can use primitive types or complex objects really easy;
Disadvantages:
- It has a lower performance:
- For 1000 events triggered sincroniously:
- dynamic: aprox. 350 miliseconds;
- string: aprox. 130 miliseconds;
- int: aprox, 130 miliseconds;
- object: aprox. 150 miliseconds;
- For 1000 events triggered sincroniously:
- Not having the parameteres stronged typed the errors in using wrong the models can be seen only at runtime;