- Home /
Design pattern, events and dependencies
Hello ! I got a question, more about generally programming than pure unity, but I take my chance.
So, I want to make an "independent" module, which control all the events. We can find in it all the apps event. It's like an event master. All the class can subscribe to each event, but they are all implement at the same place.
But, when the event raised, I don't want to broadcast it everywhere, I just want it to be sent to the class who subscribed. Maybe, I got the idea to manage all the event dependencies in an .csv or some matrice like that.
I got in memory that this is a design pattern, close to the observer but not really...
Did someone got the name, or just can give me a feedback for this idea ? (I can ear if you think it's garbage :D)
Thanks !
This should be fairly easy to implement! Just keep a dictionary in the event manager class that uses the type of event as a key, which retrieves a list of event listeners subscribed to that particular event type. Then add a method to subscribe to and unsubscribe from an event type, which adds or removes them from the appropriate list stored in the dictionary. The event manager could even be a static class, allowing its methods to be accessed from anywhere without the need to retrieve a specific instance of it. Tinker away and you'll find a comfortable implementation! :)
Your answer
Follow this Question
Related Questions
Design pattern: Loading custom data into prefab objects 0 Answers
Store card data 1 Answer
DeleGates And Events 2 Answers
Can one add events to an instantiated object? 1 Answer
Events vs Normal Functions 1 Answer