Files
AIGame/Doc/Rule/UIGenerationRules.md
T
udxandCursor b7a0bbcb89 Add hot-update boot pipeline, UI bundles/atlas assets, and design docs.
Ignore AIClient/Library and AIClient/HybridCLRData permanently; include HybridCLR/YooAsset project setup and UI tooling.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-21 16:02:58 +08:00

84 lines
3.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# UI 生成规则(AI JSON → Prefab)
> AIGame 竖屏微信小游戏版。精简系统提示词见 `Doc/Rule/UIGenerationPrompt.md`。总览见 `Doc/UI_AutoGen_Overview.md`。
## Part A - 流水线
```text
需求说明
-> AI 读规则/设计/切图清单/样例 JSON
-> 生成 Doc/UIPrefabCreater/{UIName}.json
-> Unity 获焦或菜单 Tools/UI/...
-> JsonUIPrefabBuilder 生成 Assets/Bundles/UI/Prefab/{UIName}.prefab
-> HotUpdate C# 按节点名 / bindings / events 接管
```
不使用 HTML 中间层。转换器:
- `AIClient/Assets/Editor/UI/JsonUIPrefabBuilder.cs`
- `AIClient/Assets/Editor/UI/JsonUIAutoConvert.cs`
### 目录
| 类型 | 路径 |
| --- | --- |
| JSON | `Doc/UIPrefabCreater/{UIName}.json` |
| Prefab | `Assets/Bundles/UI/Prefab/{UIName}.prefab` |
| 通用贴图 | `Assets/Bundles/UI/Texture/Common/` |
| 业务贴图 | `Assets/Bundles/UI/Texture/<Module>/` |
## Part B - AI 契约
### 必读
- `Doc/Rule/UnityUIProject.md`
- `Doc/Design/UI_Design_Principles.md`
- `Doc/UI_Normal_Set.md` 或 `Doc/UI_Pic_Set.md`
- `Doc/UIPrefabCreater/UI_ConfirmDialog.json`(样例)
- 转换器当前支持的组件(以代码为准)
### 顶层字段
`schemaVersion`(`1`)、`prefabName`、`prefabPath`、`description`、`canvas`、`assets`、`nodes`、`bindings`、`events`。
`canvas.canvasScaler.referenceResolution` **必须为 `[1080, 1920]`**。
### 命名
英文节点:`UI_` / `Panel` / `Img_` / `Txt_` / `Btn_` / `Scroll_` / `Group_`。
### 可生成组件
Canvas、CanvasScaler、GraphicRaycaster、CanvasGroup、Image、TextMeshProUGUI、Button、Shadow、Outline、ScrollRect、RectMask2D、Mask、TMP_InputField、VerticalLayoutGroup、ContentSizeFitter、LayoutElement、MonoBehaviour。
未完整实现(跳过/告警):Toggle、TMP_Dropdown、Slider、Scrollbar、ScrollView(请用 ScrollRect)。
### 按钮 / 列表模板
- 按钮:`Image`(Sliced)+ `Button`(SpriteSwap:normal/pressed/disabled;无 hover 切图可用 ColorTint)。
- 列表:`ScrollRect` → Viewport(RectMask2D)→ Content(VerticalLayoutGroup + ContentSizeFitter)→ Item_Template。
## Part C - 接管与排错
1. 确认自动转换开启,或执行 `Convert Changed JSON Prefabs Now`。
2. 看 Console `[UIGen]` 日志。
3. 打开 Prefab 核对层级/Sprite/文字。
4. HotUpdate 挂控制器:`transform.Find` / 递归按名查找;`button.onClick.AddListener`。
5. 资源加载走 YooAsset **异步**(见 `ProjectDesign.md` / `UnityUIProject.md`)。
| 现象 | 处理 |
| --- | --- |
| JSON 不转换 | 获焦/手动菜单;确认 JSON 比 Prefab 新 |
| referenceResolution 错误 | 改为 `[1080,1920]` |
| 找不到 Sprite | 短名与 Common 切图一致;Texture Type=Sprite |
| 文字不可读 | Outline/Shadow,色 `#102033` / `#0B1724` |
### 提交前自检
- JSON 在 `Doc/UIPrefabCreater`;唯一根节点;`prefabName` 一致。
- 父先于子;Sprite 已登记;九宫格 `Sliced`;TMP;bindings/events 节点存在。
## Part D - 后续
优先补齐转换器:Toggle → Slider → Scrollbar → TMP_Dropdown。图集自动化见 `Doc/UI_Atlas_Pipeline.md`。