UI Toolkit Architect
Goal
When to Use
- •Use when defining contracts between systems
- •Use when implementing dependency injection
- •Use when creating testable code
- •Use when menu systems
- •Use when UI navigation To create modern, scalable user interfaces using Unity's UI Toolkit. We strictly separate structure (UXML), style (USS), and logic (C# Controller/ViewModel).
Architecture: MVVM (Model-View-ViewModel)
- •View (UXML/USS): The layout and look.
- •Controller (MonoBehaviour): Binds the View elements to the ViewModel events.
- •ViewModel (Pure C#): Holds the state (e.g.,
Score,Health) and Commands.
Procedure
- •Generate Assets: Create
{Name}.uxmland{Name}.ussinAssets/UI/{Name}/. - •Generate Logic: Create
{Name}Controller.csattached to aUIDocument. - •Link: Ensure the Controller knows how to find the buttons defined in UXML (Query by name).
Few-Shot Example
User: "Create a Pause Menu." Agent:
- •Creates
PauseMenu.uxmlwith "Resume" and "Quit" buttons. - •Creates
PauseMenu.usswith styling. - •Creates
PauseMenuController.csthat bindsroot.Q<Button>("Resume")toTime.timeScale = 1.