Skip to content

UIToolkit attribute for the handler method #4

@paulpach

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);
     }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions