A simple event system which can broadcast and listen to events and do actions. Events and delegates are the two most important concepts that can reduce code dependency in an application.
There are two main primary class. GameEvent is a scriptable object, which holds a delegate to which listeners subscribe to. GameListenerBase is an abstract class which all listeners should inherit from.
This system lets users follow Single Responsibility Principle. Developers can create each listener as a separate script with a single responsibility. This makes the game architecture more readable and maintainable.
This idea originated from a UNITE session video. This system is a modified version of the original idea.
Events can be created as below.
In the example, the lights are turned on/off using an event. So we have created couple of events for switching on and off.
Unit testing is much easier with this system. Each event object created has a Broadcast button, which will raise the event on pressed. In this way without playing through the game, functionalities can be tested.
Listeners inherited from GameListenerBase will subscribe to the event specified. In the example, TurnLightOff script listen to TurnLightsOff event and SwitchOnRedLight script listen to TurnOnRed event.
This project is licensed under MIT License.