Skip to content

UIToolkit attribute for the handler method #4

Description

@paulpach

As an alternative to #3, what if I could put an attribute on the handler. For example, if I want to handle the ClickEvent on a button named "OK", I would do something like this:

public partial class MyWindowController: MonoBehavior {
     [UIHandler("OK",)]
     public void OnClicked(ClickEvent evt) {
         // runs when the visual element OK raises the event ClickEvent
     }
}

It would generate code like this:

[RequireComponent(typeof(UIDocument))]
public partial class MyWindowController: MonoBehavior {

     public void SubscribeUIHandler() {
          TryGetComponent(out UIDocument document);
          var root = document.root;
          root.Q("OK").RegisterCallback<ClickEvent>(OkClicked);
     }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions