Skip to content

Wariar/Simple-Game-Event-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Game Event System

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.

Usage

Events can be created as below.

enter image description here

In the example, the lights are turned on/off using an event. So we have created couple of events for switching on and off.

enter image description here

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.

enter image description here

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.

enter image description here

License

This project is licensed under MIT License.

About

A simple yet powerful event broadcaster for Unity

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages