A simple event system (Unity)

Johan Svensson
dotcrossdot
Published in
1 min readSep 9, 2018
C# event wrapper, Signals!

This is going to be a short post, but I’ll post it anyway. I wanted to share a simple event system that I use both in my own projects and professionally. The reason I created this system is that I like using events since they allows for decoupled code. However, not a huge fan of the standard C# events. They work great and all, but I’m not a fan of the syntax (defining delegates and having them as return values etc for the event etc.

The event implementation (called Signals) is in the same repo as the dependency injection framework mentioned in this post : https://medium.com/dotcrossdot/dependency-injection-framework-unity-58f7cb121de5

You create and dispatch a signal the following way:

(The signals don’t have to be static, its just a convenient way to access them).

To listen to a signal you do the following:

All of this code along with examples are available in the CakeWalk repo:

Thanks for reading!

--

--