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

112
Visualizações
Custom onClick list

Can i create custom region with grouped methods for list onClick like dynamic and statics? like this

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Yes and no! ^^

  • Yes, you can create your own event type taking a parameter and assign dynamic callbacks to it. What you are looking for is UnityEvent.

    For the dynamic parameterized ones see UnityEvent<T0> to UnityEvent<T0, T1, T2, T3> depending on how many parameters you need.

    For the example with a single int it would be (exactly as in the API example)

    // Since Unity doesn't support direct serialization of generics you have to implement this [Serializable] wrapper
    [Serializable]
    public class MyIntEvent : UnityEvent<int>
    {
    }
    
    public class ExampleClass : MonoBehaviour
    {
        public MyIntEvent m_MyEvent;
    }
    

    enter image description here

  • No, you can not simply change the existing implementation of UI.Button.onClick which is parameterless.

    What you could do, however, is build a new component and attach it on a button like

    [RequireComponent(typeof(Button))]
    public class ExampleClass : MonoBehaviour
    {
        [SerializeField] private Button _button;
        public MyIntEvent onClickWithIntParameter;
    
        private void Awake()
        {
            if(!_button) _button = GetComponent<Button>();
            _button.onClick.AddListener(HandleOnClick);
        }
    
        private void HandleOnClick()
        {
            // Wherever you get your int from
            var value = 123;
    
            onClickWithIntParameter.Invoke(value);
        }
    }
    
over 4 years ago · Santiago Trujillo Relatório
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