gamedev-unity/skills/unity-skills/skills/uitoolkit/SKILL.md
Build Unity UI Toolkit (UITK) UIs — create/edit USS stylesheets and UXML layouts, and configure UIDocument components. Use when authoring runtime or editor UI with UI Toolkit, writing USS/UXML, or wiring a UIDocument, even if the user just says "UITK" or "UXML". 构建 Unity UI Toolkit(UITK)界面(创建/编辑 USS 样式表与 UXML 布局、配置 UIDocument 组件);当用户要用 UI Toolkit 编写运行时或编辑器 UI、编写 USS/UXML、或接入 UIDocument 时使用。
npx skillsauth add bernatmv/ai-rules unity-uitoolkitInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this module for Unity UI Toolkit only: UXML for structure, USS for styling, UIDocument for scene attachment, and PanelSettings for runtime rendering.
Requires Unity 2022.3+. Do not mix this module with
ui_*UGUI/Canvas skills. Localization: Match visible UI text to the user's language. Chinese conversation -> Chinese labels/placeholders/button text. USS class names and CSS variables stay English.
uitk_read_file / uitk_find_files / uitk_get_panel_settings / uitk_list_documents / uitk_inspect_uxml / uitk_list_uss_variables / uitk_inspect_document,源码标 SkillMode.SemiAuto)直接执行;其余文件/场景写入类(uitk_create_* / uitk_write_file / uitk_add_* / uitk_modify_element 等,标 SkillMode.FullAuto)需用户 grant,grant 后服务端一步执行返结果。uitk_delete_file、uitk_remove_element、uitk_remove_uss_rule 标记为 SkillOperation.Delete,被 IsForbiddenInSemi 静态拦截 —— 仅 Bypass 模式或加入 Allowlist 才能调用。AssetDatabase.ImportAsset(path) 对单个 USS/UXML 资产单独触发导入,不会调 AssetDatabase.Refresh() 触发全项目扫描;批量创建依次单独 Import。但 USS/UXML 是 ScriptedImporter 类型,Import 仍会重建依赖此资产的 PanelSettings/UIDocument 引用,触发 IMGUI 检查器刷新与场景视图重绘。DO NOT (common hallucinations):
uitoolkit_create_button / uitoolkit_create_label do not exist -> use uitk_add_elementuitoolkit_set_style does not exist -> use uitk_add_uss_rule, uitk_remove_uss_rule, or uitk_modify_elementuitoolkit_create_canvas does not exist -> UI Toolkit uses UIDocument, not Canvasuitk_* and ui_* are different systems. Do not mix UI Toolkit structure/styling assumptions into UGUI workflowsdisplay:grid, box-shadow, calc(), @media, ::before, z-index, and gradients are unsupportedRouting:
ui modulexr_setup_ui_canvasuitk_create_from_templateuitk_create_document or uitk_set_document| Skill | Use | Key parameters |
|-------|-----|----------------|
| uitk_create_uss | Create USS file | savePath, content? |
| uitk_create_uxml | Create UXML file | savePath, content?, ussPath? |
| uitk_read_file | Read USS/UXML content | filePath |
| uitk_write_file | Overwrite file content | filePath, content |
| uitk_delete_file | Delete USS/UXML file | filePath |
| uitk_find_files | Search files by name/path | type?, folder?, filter?, limit? |
| uitk_create_batch | Create 2+ files in one call | items |
| Skill | Use | Key parameters |
|-------|-----|----------------|
| uitk_create_document | Create UIDocument GameObject | name, uxmlPath?, panelSettingsPath?, sortOrder?, parentName?/parentInstanceId?/parentPath? |
| uitk_set_document | Change UIDocument asset bindings | name/instanceId, uxmlPath?, panelSettingsPath? |
| uitk_create_panel_settings | Create PanelSettings asset | savePath, scaleMode, referenceResolutionX/Y, Unity 6 world-space options |
| uitk_get_panel_settings | Read PanelSettings values | assetPath |
| uitk_set_panel_settings | Update PanelSettings selectively | assetPath, changed fields only |
| uitk_list_documents | List scene UIDocuments | none |
| uitk_inspect_document | Inspect live VisualElement tree | name/instanceId/path, depth |
| Skill | Use | Key parameters |
|-------|-----|----------------|
| uitk_add_element | Add a child element | filePath, elementType, parentName?, elementName?, text?, classes? |
| uitk_remove_element | Remove by name | filePath, elementName |
| uitk_modify_element | Change attributes/classes/text | filePath, elementName, text?, classes?, style?, newName?, bindingPath?, custom attribute fields |
| uitk_clone_element | Duplicate an element subtree | filePath, elementName, newName? |
| uitk_inspect_uxml | Parse UXML hierarchy | filePath, depth? |
| Skill | Use | Key parameters |
|-------|-----|----------------|
| uitk_add_uss_rule | Add or replace selector rule | filePath, selector, properties |
| uitk_remove_uss_rule | Remove selector rule | filePath, selector |
| uitk_list_uss_variables | Inspect design tokens / var() usage | filePath |
| Skill | Use | Key parameters |
|-------|-----|----------------|
| uitk_create_from_template | Generate paired UXML+USS | template, savePath, name? |
| uitk_create_editor_window | Generate EditorWindow script | savePath, className, uxmlPath?, ussPath?, menuPath? |
| uitk_create_runtime_ui | Generate runtime MonoBehaviour query scaffold | savePath, className, elementQueries? |
Supported starter templates include menu, hud, dialog, settings, inventory, list, tab-view, toolbar, card, and notification.
| Pattern | Supported in USS | What to do |
|---------|------------------|------------|
| Flex layout | Yes | Use flex-direction, flex-wrap, align-items, justify-content |
| border-radius, opacity, overflow:hidden | Yes | Safe to use |
| Transforms / transitions | Yes | translate, scale, rotate work |
| CSS variables | Yes | Prefer :root tokens |
| display:grid / display:block / display:inline | No | Everything is flex; emulate grids with wrapping rows |
| box-shadow | No | Fake with nested background element |
| linear-gradient() / radial-gradient() | No | Use image textures |
| calc() / @media | No | Use explicit values + PanelSettings.scaleMode |
| ::before / ::after | No | Add a real child VisualElement |
| z-index | No | Later siblings render on top |
| Need | USS-safe workaround |
|------|---------------------|
| Shadow | Extra child VisualElement behind content |
| Responsive scaling | PanelSettings.scaleMode = ScaleWithScreenSize |
| Grid cards | flex-direction: row + flex-wrap: wrap + child widths |
| Circular avatar | Equal width/height + radius = half size + overflow:hidden |
| Pseudo decoration | Add an extra absolutely positioned child |
| Skill | Parameters you usually need first |
|-------|-----------------------------------|
| uitk_create_panel_settings | savePath, scaleMode, referenceResolutionX, referenceResolutionY |
| uitk_create_document | name, uxmlPath, panelSettingsPath, sortOrder? |
| uitk_add_element | filePath, elementType, parentName?, elementName?, text?, classes? |
| uitk_modify_element | filePath, elementName, changed attributes only |
| uitk_add_uss_rule | filePath, selector, properties |
PanelSettings choicesScaleWithScreenSize: default for runtime HUD/menu UIConstantPixelSize: use when strict pixel mapping mattersConstantPhysicalSize: rare; only for physically sized UI requirementsUnity 6 world-space flows also need the scene-side document camera setup after configuring PanelSettings.
<Style src="..."/>.uitk_inspect_uxml before complex structural edits if you did not create the file yourself.uitk_create_uxml can auto-reference a stylesheet when ussPath is provided.uitk_create_document.PanelSettings asset.<Style src="MyStyle.uss" />; use a full asset path only for cross-folder references.uitk_read_file -> edit -> uitk_write_file.uitk_create_batch.UIDocument camera setup.uitk_create_from_template when the user needs a starter screen fast; use uitk_add_element / uitk_add_uss_rule for targeted edits on existing files.import unity_skills
unity_skills.call_skill("uitk_create_panel_settings",
savePath="Assets/UI/GamePanel.asset",
scaleMode="ScaleWithScreenSize",
referenceResolutionX=1920,
referenceResolutionY=1080
)
unity_skills.call_skill("uitk_create_uss",
savePath="Assets/UI/HUD.uss",
content=":root { --accent: #E8632B; } .title { color: var(--accent); }"
)
unity_skills.call_skill("uitk_create_uxml",
savePath="Assets/UI/HUD.uxml",
content="<?xml version=\"1.0\" encoding=\"utf-8\"?><engine:UXML xmlns:engine=\"UnityEngine.UIElements\"><Style src=\"HUD.uss\" /><engine:Label class=\"title\" text=\"Start\" /></engine:UXML>"
)
unity_skills.call_skill("uitk_create_document",
name="HUD",
uxmlPath="Assets/UI/HUD.uxml",
panelSettingsPath="Assets/UI/GamePanel.asset"
)
Exact names, parameters, defaults, and returns are defined by GET /skills/schema or unity_skills.get_skill_schema(), not by this file.
Load USS_REFERENCE.md before generating non-trivial USS systems, layout patterns, component styles, or complete examples.
development
Keyword research and validation with real search-demand data — never ship keywords from intuition alone. Probes Google Autocomplete per language (free, no account) to prove demand and discover the exact phrasing people type, checks SERPs for winnability, and uses Keyword Planner/Ahrefs/Semrush exports when the user has access. Activates when: choosing or reviewing SEO keywords, meta keywords, page titles, article topics or slugs, landing page copy targeting search, App Store/ASO keyword fields, multilingual keyword sets, 'what should we rank for', 'keyword analysis', or auditing why a page doesn't rank. Also invoke it as a validation pass whenever another skill or task produces a keyword list.
development
Automate YooAsset hot-update and asset bundles — build bundles, run Editor simulate builds, manage Collector groups, analyze BuildReport, and validate runtime. Use when building or simulating YooAsset bundles, configuring collectors, or validating hot-update assets, even if the user just says "热更" or "打AB包". 自动化 YooAsset 热更新与资源包(构建 bundle、编辑器模拟构建、管理 Collector 分组、分析 BuildReport、运行时校验);当用户要构建或模拟 YooAsset 资源包、配置 collector、或校验热更资源时使用。
development
Source-anchored design rules for YooAsset v2.3.18 — initialization, default-package shortcuts, play modes, asset handles, loading, updates, filesystem, build, and pitfalls. Use when writing or reviewing YooAsset code, initializing packages, loading assets via handles, setting up hot-update/download, or choosing a play mode, even if the user just says "热更" or "资源包". 为 YooAsset v2.3.18 提供源码锚定的设计规则(初始化、默认包快捷方式、运行模式、资源句柄、加载、更新、文件系统、构建、陷阱);当用户要编写或审查 YooAsset 代码、初始化 package、用句柄加载资源、配置热更/下载、或选择运行模式时使用。
data-ai
Last-resort guidance for safely hand-editing Unity serialized YAML (.unity/.prefab/.asset/.meta/ProjectSettings) — reference/fileID repair, GUID safety, and merge-conflict fixes. Use when REST cannot reach the change and YAML must be hand-edited — fixing m_Script GUIDs, broken fileID references, .meta files, or merge conflicts, even if the user just says "场景文件打不开" or "引用丢了". 安全手编 Unity 序列化 YAML(.unity/.prefab/.asset/.meta/ProjectSettings)的最后手段(引用/fileID 修复、GUID 安全、合并冲突修复);当 REST 无法触达、必须手编 YAML 时使用——修复 m_Script GUID、断裂 fileID 引用、.meta 文件或合并冲突。