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);
}
}
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:
It would generate code like this: