Im in the planning stages for my next project. I’m planning on an event driven system and I am going to have a logging class that i would like to log all events for debugging reasons. Is there a way to “subscribe to all events” or do I need to track them all and remember too add them to the logger? Apologize if this is a silly question, I am new to events.
Are we talking about Unity Events or generic C# events?
The one that is explained here: Unity Connect
I’m not clear on the differences.
I think you’d have to track them all.
The message system that I implemented uses a mediator so that the sender and subscribers don’t have to know about each other. I would think that would be a good place to keep track of all your events for a logger.
Thanks for the hints all.
The C# events are just a beefed up delegates. There’s nothing helpful for global hooks or anything like that.
I personally use my own system where I can have strongly typed ‘event’, that I call "Notification"s. With it I have a global listener hook.
Here is the Notification base class that all Notification types should inherit from, and also acts as the static factory through which you can easily attach listeners to various objects.
And here is the INotificationDispatcher, and basic implementation of it, that gets attached as the mediator for Notifications that are dispatched by GameObjects (the majority of which are done, if you want to dispatch from a none GameObject/Component, you have to implement INotificationDispatcher yourself).
I talk about it in this article, though the code I reference is an older version of it. But the shape of it didn’t change, so the how to use it is very similar.
http://jupiterlighthousestudio.com/spacepuppy_unity_framework_and_unity_notification_system/