Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

486
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda