Hi,
this looks like a good improvement on the class I'm already using thanks but I've got a couple of questions that I'm not sure how to resolve when using the Subscribe<T>
/ Raise<T>
pattern...
1. how to subscribe to any event eg using something like
eventManager.Subscribe<IEvent>(SomeHandler);
...
private void SomeHandler(IEvent e) {}
where all events inherit from IEvent
eg public struct CustomEvent : IEvent
so calling eventManager.Raise(new CustomEvent {})
would somehow need to get picked up by the "global" IEvent
handler
2. how to pass an IEvent
reference to a specific <T>
handler.
eg Odin Inspector lets you select a class from a drop down when you do
[SerializeReference] IEvent @event;
...
eventManager.Raise(@event);
so whilst @event.GetType()
may be CustomEvent : IEvent
it will still be Raised as an IEvent
when calling
eventManager.Raise(@event)
That means it won't be picked up by eventManager.Subscribe<CustomEvent>(...)
would be great if the library could somehow handle these scenarios.
(I have some messy solutions for the EventManager
class I'm currently working which basically involves adding an extra method like
EventManager.AddInterfaceEventListener(e.GetType(), InterfaceHandler)
then adding it to separate dictionary to the main one, but I it doesn't seem like a great implementation)
thanks
J
(sorry I forgot to mention I'm using Unity! hence the Odin Inspector screenshot above)