UI Toolkit Architect
Overview
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.
Best Practices
- Follow the patterns and constraints documented in this skill.
- Always run @context-discovery-agent before applying this skill to verify environment compatibility.
- Apply TDD where applicable: write the interface contract first, then implement.
- Zero GC in hot paths: cache references, avoid LINQ and
ew allocations in Update loops.
TDD Contract
⚠️ Legacy Skill — Refactor Pending
Este skill NO tiene tests automatizados aún. El siguiente boilerplate es un punto de partida.
// Escribe estos tests ANTES de implementar:
// Test 1: should [expected behavior] when [condition]
[Test]
public void UiToolkitArchitectLegacy_Should{ExpectedBehavior}_When{Condition}()
{{
// Arrange
// TODO: Setup test fixtures
// Act
// TODO: Execute system under test
// Assert
Assert.Fail("Not implemented — write test first");
}}
// Test 2: should handle [edge case]
[Test]
public void UiToolkitArchitectLegacy_ShouldHandle{EdgeCase}()
{{
// Arrange
// TODO: Setup edge case scenario
// Act
// TODO: Execute
// Assert
Assert.Fail("Not implemented");
}}
// Test 3: should throw when [invalid input]
[Test]
public void UiToolkitArchitectLegacy_ShouldThrow_When{InvalidInput}()
{{
// Arrange
var invalidInput = default;
// Act & Assert
Assert.Throws<Exception>(() => {{ /* execute */ }});
}}
Pasos para completar el TDD:
- Descomenta los tests above
- Implementa la funcionalidad mínima para que compile
- Ejecuta los tests — deben fallar (RED)
- Implementa la funcionalidad real
- Verifica que los tests pasen (GREEN)
- Refactorea manteniendo los tests verdes
Nota: Este skill fue marcado como tdd_first: false durante la auditoría v2.0.1. La sección TDD fue agregada automáticamente pero requiere customización manual para reflejar el comportamiento real del skill.
Related Skills
- @context-discovery-agent - Verify Unity version and package compatibility before proceeding
- @unified-style-guide - Naming and formatting conventions
- @automated-unit-testing - TDD scaffolding for this skill's components