Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

487
Vistas
Subscribe static methods to EventHandler Unity

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.

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda