VPDPersonal / UnityFastTools

1 stars 0 forks source link

Event handler for UIToolkit #3

Open paulpach opened 3 weeks ago

paulpach commented 3 weeks ago

UIToolkit requires a lot of repetitive boilerplate for handling events. It would be awesome to have source generators for handling events. For example:

For example, It would be awesome to have something like this:

public partial class MyWindowController: MonoBehavior {
     [UIHandler("OK", nameof(OnClicked))]
     public Button okButton;

would generate something like this:

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

     public void SubscribeUIHandler() {
           TryGetComponent(out UIDocument document);
          var root = document.root;
          okButton = root.Q<Button>("OK");
          okButton.clicked += OnClicked;
     }
}

There are other types of events, so there could be more here.

VPDPersonal commented 3 weeks ago

It looks like it's really necessary. We'll definitely get it in the works. As soon as I finish the full UI package, I will come back to this issue.