Dustin |
2 Comments |
Tuesday, October 9, 2012 at 3:49PM 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.
Dustin |
2 Comments |
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.
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