I have an EventHandler that is static which can be subscribed to from anywhere.
public static event EventHandler<CustomEvent> OnChunkLoad = delegate(object sender, CustomEvent ev) { };
I can subscribe non-static methods like so and this work perfectly when the handler is raised.
EventHandlers.OnChunkLoad += whenChunkIsLoaded;
public void whenChunkIsLoaded(Object obj, CustomEvent ev)
{
print("Loaded\n");
}
But now I want to be able to subscribe static methods at runtime automatically and allow them to be called when the handler is invoked.
Right now the only way to do this is to have some static method called at startup to subscribe all static methods I want to subscribe.
public static class StaticMethods
{
// call this on startup
public static void registerMethods()
{
EventHandlers.OnChunkLoad += whenChunkIsLoaded;
}
public static void whenChunkIsLoaded(Object obj, CustomEvent ev)
{
print(ev.DateTime + " : " + obj.GetType());
}
}
Even though this would work it is messy and eventually become very long after awhile. Any help, Thanks.