- Notifications
You must be signed in to change notification settings - Fork456
Description
Hello, I want to propose adding a system that I have implemented in previous projects of mine that use the Unity UI Toolkit.
It consists of a base classMenuController which is linked to a UXLM document or a Visual Element (the view). When inheriting from it, allows you to add a new attribute I've defined calledQueryFromView applicable to fields of typeVisualElement (or subclasses) so that field is automatically initialized to an specific element from the view.
You can query by name, type, or both.
It counts with explanatory error and warning logs for every possible misuse of the system.
Depending on the project, I use two different variants:
Variant 1:EditorWindow and controller are independent
When using this option, whenever you inherit fromMenuController you have to inherit the base constructor in your class, like this:
You initialize your controller this way (unless you've added extra arguments to your constructor), wherevisualTreeAsset represents your view as a UXML document:
Variant 2:EditorWindowis the controller
When opting for using this variant, you don't have to worry about constructors or inicialization. However, you have to worry about dragging the UXML file that represents your view from your EditorWindow script to theMenu UI field in the inspector.
Note that this variant does not allow you to use as a view a VisualElement that is not represented by a UXML file.
Does it sound useful for your repository? In case you like it, which variant should I implement? Please let me know what you think about it.
PS: Don't mind the namespaces and spanish comments. I used screenshots from a time I shared my system in a Spanish-speaking community.



