Game message system


















Right now this isn't really an issue because my game is so simple that it runs perfectly fine as it is. Looks like you're trying to develop an event system. I guess you're right, it really is used to act as an event system.

What other ways can you use a messaging system? Add a comment. Active Oldest Votes. Improve this answer. Markus von Broady Markus von Broady 2, 15 15 silver badges 30 30 bronze badges. I'm using a pool for my messages, and I never actually investigated whether or not they were useful. Past- time to profile!

What if I have a message that is emitted maybe every frame? I guess the answer would be to have a specific pool for that kind of object, which makes sense. Creating an Array and populating it with Messages takes 1ms in a slow Debug environment.

I hope that clears things up. Investing time in fine tuning your code is only worth it if that code is currently slowing down your game and make these changes can boost up performance significantly. For instance, creating Sprtie instances in AS3 would be very time consuming, it is much better to recycle them. Creating Point objects is not, recycling them would be a waste of coding time and readability. I'm worried about Java's garbage collector running in the middle of the game and causing slowdowns.

But your point about premature optimization is still valid. Show 1 more comment. Liosan Liosan 1, 12 12 silver badges 10 10 bronze badges. Compare that to the monstrosity in my answer. Discovery is costly, for sure. I can live with my code being bigger for faster execution. But that was just my subjective remark. So just to clarify, you'd basically have a bunch of overloaded methods that are called messageReceived with different subclasses of Message.

Speaking of which, Can't send a message to a specific recipient, but I haven't needed that yet in my game so I don't mind it too much. Subscribing to a message type would look something like this: globalMessageQueue. You could try using MessageDispatcher.

Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. When the call is made a target GameObject is specified; the call will be issued on all components of the GameObject that implement the specified interface that the call is to be issued against. The messaging system allows for custom user data to be passed, as well as how far through the GameObject hierarchy the event should propagate; that is should it just execute for the specified GameObject, or should it also execute on children and parents.

In addition to this the messaging framework provides helper functions to search for and find GameObjects that implement a given messaging interface. The messaging system is generic and designed for use not just by the UI system but also by general game code. It is relatively trivial to add custom messaging events and they will work using the same framework that the UI system uses for all event handling. If you wish to define a custom message it is relatively simple.

The system is pure C and aims to address some of the issues present with SendMessage. The system works using custom interfaces that can be implemented on a MonoBehaviour to indicate that the component is capable of receiving a callback from the messaging system. When the call is made a target GameObject The fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. More info See in Glossary is specified; the call will be issued on all components of the GameObject that implement the specified interface that the call is to be issued against.

The messaging system allows for custom user data to be passed, as well as how far through the GameObject hierarchy the event should propagate; that is should it just execute for the specified GameObject , or should it also execute on children and parents.

In addition to this the messaging framework provides helper functions to search for and find GameObjects that implement a given messaging interface. The messaging system is generic and designed for use not just by the UI system but also by general game code.

It is relatively trivial to add custom messaging events and they will work using the same framework that the UI system uses for all event handling. If you wish to define a custom message it is relatively simple.



0コメント

  • 1000 / 1000