A simple event system (Unity)

Johan Svensson
Sep 9, 2018 · 1 min read
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!

Johan Svensson

Written by

Hi all!

dotcrossdot

My name is Johan Svensson. I’m a game developer at Resolution Games. This is a collection of projects that I’ve worked on and want to showcase. Some are purely hobby projects and some are used in real productions. Hope you enjoy it!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade