twitter
links
Twitter.com LinkedIn.com RSS

« 2012 Holiday Unity Game Jam | Main | Pong Tournament takes 2nd in the Atari Indie Dev Challenge »

Unity3D C# Event Manager

From many years of Flash development, I came to appreciate Flash's event system.  Unity's method of object communication using SendMessage works well in many cases, but starts to become problematic when trying to refractor a large project with countless gameObject's referencing other gameObjects. 

One of the first things I wrote in Unity, after switching to C#, was an event managment system to handle class abstraction. At its core, the EventManager does use SendMessage and does have direct references to gameObjects, but seperates the need for classes to know anything about each other as long as they use an event object to know how to talk to each other when an event happens. 

So, try it out.  If you have any suggestions or fixes, let me know.

EventManager.cs

 

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (2)

I almost did the same thing when I began playing around with Unity3D.
But then I found the delegates in C#. They handle pretty much the same way as events and are actually a bit more powerful. Robert Penner's AS3Signals simulate these delegates actually. You may want to play with them yourself.

October 10, 2012 | Unregistered CommenterBart Wttewaall

From what I have heard, SendMessage will only slow you down if used regularly. C#'s Event and Delegate system is great on performance and really keeps code clean. Prime31 has a really good video tutorial on it http://www.youtube.com/watch?v=N2zdwKIsXJs He has a good tutorial on Actions as well for setting up callbacks http://www.youtube.com/watch?v=7KBmZvpguWk

November 7, 2012 | Unregistered CommenterFrank Ramirez

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>