You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 class MenuController 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 called QueryFromView applicable to fields of type VisualElement (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 from MenuController 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), where visualTreeAsset 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 the Menu 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.
The text was updated successfully, but these errors were encountered:
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 class
MenuController
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 independentWhen using this option, whenever you inherit from
MenuController
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), where
visualTreeAsset
represents your view as a UXML document:Variant 2:
EditorWindow
is the controllerWhen 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 the
Menu 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.
The text was updated successfully, but these errors were encountered: