unity-ui
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUnity UI Skills
Unity UI 技能
BATCH-FIRST: Usewhen creating 2+ UI elements.ui_create_batch
优先批量操作:创建2个及以上UI元素时使用。ui_create_batch
Guardrails
使用规范
Mode: Full-Auto required
DO NOT (common hallucinations):
- is the correct name — NOT
ui_create_canvasui_add_canvas - does not exist → use
ui_create_labelui_create_text - does not exist → use
ui_create_checkboxui_create_toggle - does not exist → use
ui_set_coloron Image/Text componentcomponent_set_property - Do not confuse UGUI (this module) with UI Toolkit (uitoolkit module)
Routing:
- For UI Toolkit (UXML/USS) → use module
uitoolkit - For XR-compatible UI → use module's
xrto convert Canvas to World Spacexr_setup_ui_canvas - For text updates → (this module)
ui_set_text - For layout arrangement → ,
ui_layout_children,ui_align_selectedui_distribute_selected
模式要求:必须使用全自动模式
禁止操作(常见的错误生成内容):
- 正确的方法名是,不是
ui_create_canvasui_add_canvas - 不存在方法,请使用
ui_create_labelui_create_text - 不存在方法,请使用
ui_create_checkboxui_create_toggle - 不存在方法,请针对Image/Text组件使用
ui_set_color修改颜色component_set_property - 不要混淆UGUI(本模块)和UI Toolkit(uitoolkit模块)
路由规则:
- 若使用UI Toolkit(UXML/USS)→ 请使用模块
uitoolkit - 若需要XR兼容的UI → 请使用模块的
xr将Canvas转换为世界空间模式xr_setup_ui_canvas - 若需要更新文本内容 → 请使用本模块的
ui_set_text - 若需要布局排列 → 请使用、
ui_layout_children、ui_align_selectedui_distribute_selected
Skills Overview
技能概览
| Single Object | Batch Version | Use Batch When |
|---|---|---|
| | Creating 2+ UI elements |
Query/Utility Skills:
- - Update text content
ui_set_text - - Find UI elements
ui_find_all - - Set RectTransform size/position
ui_set_rect - - Set anchor preset
ui_set_anchor - - Arrange children in layout
ui_layout_children - - Align selected elements
ui_align_selected - - Distribute selected elements
ui_distribute_selected - - Set Image properties (type/fill/sprite)
ui_set_image - - Add/configure LayoutElement
ui_add_layout_element - - Add/configure CanvasGroup
ui_add_canvas_group - - Add Mask or RectMask2D
ui_add_mask - - Add Shadow/Outline effect
ui_add_outline - - Configure Selectable colors/transition/navigation
ui_configure_selectable
| 单对象方法 | 批量版本 | 适用场景 |
|---|---|---|
| | 创建2个及以上UI元素 |
查询/工具类技能:
- - 更新文本内容
ui_set_text - - 查找UI元素
ui_find_all - - 设置RectTransform的尺寸/位置
ui_set_rect - - 设置锚点预设
ui_set_anchor - - 按布局排列子元素
ui_layout_children - - 对齐选中的元素
ui_align_selected - - 均匀分布选中的元素
ui_distribute_selected - - 设置Image属性(类型/填充/精灵图)
ui_set_image - - 添加/配置LayoutElement
ui_add_layout_element - - 添加/配置CanvasGroup
ui_add_canvas_group - - 添加Mask或RectMask2D
ui_add_mask - - 添加阴影/描边效果
ui_add_outline - - 配置可交互组件的颜色/过渡/导航规则
ui_configure_selectable
Single-Object Skills
单对象操作技能
ui_create_canvas
ui_create_canvas
Create a UI Canvas container.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No | "Canvas" | Canvas name |
| string | No | "ScreenSpaceOverlay" | ScreenSpaceOverlay/ScreenSpaceCamera/WorldSpace |
创建UI Canvas容器。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否 | "Canvas" | Canvas名称 |
| string | 否 | "ScreenSpaceOverlay" | 渲染模式:ScreenSpaceOverlay/ScreenSpaceCamera/WorldSpace |
ui_create_panel
ui_create_panel
Create a Panel container.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No | "Panel" | Panel name |
| string | No | null | Parent Canvas/object |
| float | No | 1,1,1,0.5 | Background color |
| float | No | 200 | Size in pixels |
创建Panel容器。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否 | "Panel" | Panel名称 |
| string | 否 | null | 父级Canvas/对象 |
| float | 否 | 1,1,1,0.5 | 背景颜色 |
| float | 否 | 200 | 尺寸(单位:像素) |
ui_create_button
ui_create_button
Create a Button.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No | "Button" | Button name |
| string | No | null | Parent object |
| string | No | "Button" | Button label |
| float | No | 160/30 | Size |
| float | No | 0 | Position offset |
创建Button。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否 | "Button" | Button名称 |
| string | 否 | null | 父级对象 |
| string | 否 | "Button" | Button标签文本 |
| float | 否 | 160/30 | 尺寸 |
| float | 否 | 0 | 位置偏移 |
ui_create_text
ui_create_text
Create a Text element.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No | "Text" | Text name |
| string | No | null | Parent object |
| string | No | "Text" | Content |
| int | No | 24 | Font size |
| float | No | 0,0,0,1 | Text color |
| float | No | 200/50 | Size |
创建Text元素。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否 | "Text" | Text元素名称 |
| string | 否 | null | 父级对象 |
| string | 否 | "Text" | 文本内容 |
| int | 否 | 24 | 字体大小 |
| float | 否 | 0,0,0,1 | 文本颜色 |
| float | 否 | 200/50 | 尺寸 |
ui_create_image
ui_create_image
Create an Image element.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No | "Image" | Image name |
| string | No | null | Parent object |
| string | No | null | Sprite asset path |
| float | No | 1,1,1,1 | Tint color |
| float | No | 100 | Size |
创建Image元素。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否 | "Image" | Image元素名称 |
| string | 否 | null | 父级对象 |
| string | 否 | null | 精灵图资源路径 |
| float | 否 | 1,1,1,1 | 着色颜色 |
| float | 否 | 100 | 尺寸 |
ui_create_inputfield
ui_create_inputfield
Create an InputField.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No | "InputField" | Field name |
| string | No | null | Parent object |
| string | No | "Enter text..." | Placeholder |
| float | No | 200/30 | Size |
创建InputField。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否 | "InputField" | 输入框名称 |
| string | 否 | null | 父级对象 |
| string | 否 | "Enter text..." | 占位提示文本 |
| float | 否 | 200/30 | 尺寸 |
ui_create_slider
ui_create_slider
Create a Slider.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No | "Slider" | Slider name |
| string | No | null | Parent object |
| float | No | 0 | Minimum value |
| float | No | 1 | Maximum value |
| float | No | 0.5 | Initial value |
| float | No | 160/20 | Size |
创建Slider。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否 | "Slider" | 滑块名称 |
| string | 否 | null | 父级对象 |
| float | 否 | 0 | 最小值 |
| float | 否 | 1 | 最大值 |
| float | 否 | 0.5 | 初始值 |
| float | 否 | 160/20 | 尺寸 |
ui_create_toggle
ui_create_toggle
Create a Toggle/Checkbox.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No | "Toggle" | Toggle name |
| string | No | null | Parent object |
| string | No | "Toggle" | Label text |
| bool | No | false | Initial state |
创建Toggle/Checkbox。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否 | "Toggle" | 开关名称 |
| string | 否 | null | 父级对象 |
| string | 否 | "Toggle" | 标签文本 |
| bool | 否 | false | 初始状态 |
ui_set_text
ui_set_text
Update text content.
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | Yes | Text object name |
| string | Yes | New content |
更新文本内容。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| string | 是 | Text对象名称 |
| string | 是 | 新的文本内容 |
ui_find_all
ui_find_all
Find UI elements in scene.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No | null | Filter: Button/Text/Image/etc. |
| int | No | 100 | Max results |
查找场景中的UI元素。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否 | null | 过滤条件:Button/Text/Image等 |
| int | 否 | 100 | 最大返回结果数 |
ui_set_rect
ui_set_rect
Set RectTransform size, position, and padding.
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | No* | UI element name |
| int | No* | Instance ID |
| float | No | Size |
| float | No | Position |
| float | No | Padding offsets |
设置RectTransform的尺寸、位置和内边距。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| string | 否* | UI元素名称 |
| int | 否* | 实例ID |
| float | 否 | 尺寸 |
| float | 否 | 位置 |
| float | 否 | 内边距偏移 |
ui_set_anchor
ui_set_anchor
Set anchor preset for a UI element.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No* | - | UI element name |
| int | No* | - | Instance ID |
| string | No | "MiddleCenter" | Anchor preset |
| bool | No | true | Also set pivot |
Presets: TopLeft, TopCenter, TopRight, MiddleLeft, MiddleCenter, MiddleRight, BottomLeft, BottomCenter, BottomRight, StretchHorizontal, StretchVertical, StretchAll
为UI元素设置锚点预设。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否* | - | UI元素名称 |
| int | 否* | - | 实例ID |
| string | 否 | "MiddleCenter" | 锚点预设 |
| bool | 否 | true | 同时设置枢轴点 |
预设值:TopLeft、TopCenter、TopRight、MiddleLeft、MiddleCenter、MiddleRight、BottomLeft、BottomCenter、BottomRight、StretchHorizontal、StretchVertical、StretchAll
ui_layout_children
ui_layout_children
Arrange child UI elements in a layout.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No* | - | Parent element name |
| int | No* | - | Instance ID |
| string | No | "Vertical" | Layout type |
| float | No | 10 | Spacing between elements |
Layout types: Vertical, Horizontal, Grid
按布局排列子UI元素。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否* | - | 父元素名称 |
| int | 否* | - | 实例ID |
| string | 否 | "Vertical" | 布局类型 |
| float | 否 | 10 | 元素间距 |
布局类型:Vertical、Horizontal、Grid
ui_align_selected
ui_align_selected
Align selected UI elements.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No | "Center" | Alignment type |
Alignments: Left, Center, Right, Top, Middle, Bottom
对齐选中的UI元素。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否 | "Center" | 对齐类型 |
对齐选项:Left、Center、Right、Top、Middle、Bottom
ui_distribute_selected
ui_distribute_selected
Distribute selected UI elements evenly.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No | "Horizontal" | Distribution direction |
均匀分布选中的UI元素。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否 | "Horizontal" | 分布方向 |
Batch Skill
批量操作技能
ui_create_batch
ui_create_batch
Create multiple UI elements in one call.
| Parameter | Type | Required | Description |
|---|---|---|---|
| array | Yes | Array of UI element configs |
Item properties: (required), , , , , , , , , , , , etc.
typenameparenttextwidthheightxyrgbaSupported types: Button, Text, Image, Panel, Slider, Toggle, InputField, Dropdown, ScrollView, RawImage, Scrollbar
Returns:
{success, totalItems, successCount, failCount, results: [{success, name, type, instanceId}]}python
unity_skills.call_skill("ui_create_batch", items=[
{"type": "Button", "name": "StartBtn", "parent": "MenuPanel", "text": "Start", "y": 60},
{"type": "Button", "name": "OptionsBtn", "parent": "MenuPanel", "text": "Options", "y": 0},
{"type": "Button", "name": "QuitBtn", "parent": "MenuPanel", "text": "Quit", "y": -60}
])单次调用创建多个UI元素。
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| array | 是 | UI元素配置数组 |
元素配置属性:(必填)、、、、、、、、、、、等
typenameparenttextwidthheightxyrgba支持的元素类型:Button、Text、Image、Panel、Slider、Toggle、InputField、Dropdown、ScrollView、RawImage、Scrollbar
返回值:
{success, totalItems, successCount, failCount, results: [{success, name, type, instanceId}]}python
unity_skills.call_skill("ui_create_batch", items=[
{"type": "Button", "name": "StartBtn", "parent": "MenuPanel", "text": "Start", "y": 60},
{"type": "Button", "name": "OptionsBtn", "parent": "MenuPanel", "text": "Options", "y": 0},
{"type": "Button", "name": "QuitBtn", "parent": "MenuPanel", "text": "Quit", "y": -60}
])Example: Efficient Menu Creation
示例:高效创建菜单
python
import unity_skillspython
import unity_skillsBAD: 5 API calls
不推荐写法:5次API调用
unity_skills.call_skill("ui_create_canvas", name="MainMenu")
unity_skills.call_skill("ui_create_panel", name="MenuPanel", parent="MainMenu")
unity_skills.call_skill("ui_create_button", name="StartBtn", parent="MenuPanel", text="Start", y=60)
unity_skills.call_skill("ui_create_button", name="OptionsBtn", parent="MenuPanel", text="Options", y=0)
unity_skills.call_skill("ui_create_button", name="QuitBtn", parent="MenuPanel", text="Quit", y=-60)
unity_skills.call_skill("ui_create_canvas", name="MainMenu")
unity_skills.call_skill("ui_create_panel", name="MenuPanel", parent="MainMenu")
unity_skills.call_skill("ui_create_button", name="StartBtn", parent="MenuPanel", text="Start", y=60)
unity_skills.call_skill("ui_create_button", name="OptionsBtn", parent="MenuPanel", text="Options", y=0)
unity_skills.call_skill("ui_create_button", name="QuitBtn", parent="MenuPanel", text="Quit", y=-60)
GOOD: 2 API calls
推荐写法:2次API调用
unity_skills.call_skill("ui_create_canvas", name="MainMenu")
unity_skills.call_skill("ui_create_batch", items=[
{"type": "Panel", "name": "MenuPanel", "parent": "MainMenu", "width": 300, "height": 200},
{"type": "Button", "name": "StartBtn", "parent": "MenuPanel", "text": "Start", "y": 60},
{"type": "Button", "name": "OptionsBtn", "parent": "MenuPanel", "text": "Options", "y": 0},
{"type": "Button", "name": "QuitBtn", "parent": "MenuPanel", "text": "Quit", "y": -60}
])
undefinedunity_skills.call_skill("ui_create_canvas", name="MainMenu")
unity_skills.call_skill("ui_create_batch", items=[
{"type": "Panel", "name": "MenuPanel", "parent": "MainMenu", "width": 300, "height": 200},
{"type": "Button", "name": "StartBtn", "parent": "MenuPanel", "text": "Start", "y": 60},
{"type": "Button", "name": "OptionsBtn", "parent": "MenuPanel", "text": "Options", "y": 0},
{"type": "Button", "name": "QuitBtn", "parent": "MenuPanel", "text": "Quit", "y": -60}
])
undefinedTextMeshPro Support
TextMeshPro 支持
UI Skills auto-detect TextMeshPro:
- With TMP: Uses
TextMeshProUGUI - Without TMP: Falls back to legacy
UnityEngine.UI.Text
Response includes field to indicate which was used.
usingTMPUI技能会自动检测TextMeshPro:
- 已安装TMP:使用组件
TextMeshProUGUI - 未安装TMP:降级使用旧版组件
UnityEngine.UI.Text
返回结果包含字段,标识实际使用的文本组件类型。
usingTMPNew Element Creation Skills
新增元素创建技能
ui_create_dropdown
ui_create_dropdown
Create a Dropdown with options list and full Template/ScrollRect hierarchy.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No | "Dropdown" | Dropdown name |
| string | No | null | Parent object |
| string | No | "Option A,Option B,Option C" | Comma-separated options |
| float | No | 160/30 | Size |
创建带有选项列表和完整Template/ScrollRect层级的Dropdown。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否 | "Dropdown" | 下拉框名称 |
| string | 否 | null | 父级对象 |
| string | 否 | "Option A,Option B,Option C" | 逗号分隔的选项列表 |
| float | 否 | 160/30 | 尺寸 |
ui_create_scrollview
ui_create_scrollview
Create a ScrollRect with Viewport, RectMask2D, and Content.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No | "ScrollView" | Name |
| string | No | null | Parent object |
| float | No | 300/200 | Size |
| bool | No | false | Enable horizontal scroll |
| bool | No | true | Enable vertical scroll |
| string | No | "Elastic" | Unrestricted/Elastic/Clamped |
创建包含Viewport、RectMask2D和Content的ScrollRect。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否 | "ScrollView" | 滚动视图名称 |
| string | 否 | null | 父级对象 |
| float | 否 | 300/200 | 尺寸 |
| bool | 否 | false | 启用横向滚动 |
| bool | 否 | true | 启用纵向滚动 |
| string | 否 | "Elastic" | 滚动类型:Unrestricted/Elastic/Clamped |
ui_create_rawimage
ui_create_rawimage
Create a RawImage element (for Texture2D/RenderTexture).
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No | "RawImage" | Name |
| string | No | null | Parent object |
| string | No | null | Texture asset path |
| float | No | 100 | Size |
创建RawImage元素(用于展示Texture2D/RenderTexture)。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否 | "RawImage" | RawImage元素名称 |
| string | 否 | null | 父级对象 |
| string | 否 | null | 纹理资源路径 |
| float | 否 | 100 | 尺寸 |
ui_create_scrollbar
ui_create_scrollbar
Create a standalone Scrollbar.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No | "Scrollbar" | Name |
| string | No | null | Parent object |
| string | No | "BottomToTop" | LeftToRight/RightToLeft/BottomToTop/TopToBottom |
| float | No | 0 | Initial value (0-1) |
| float | No | 0.2 | Handle size (0-1) |
| int | No | 0 | 0=continuous, >0=discrete |
创建独立的Scrollbar。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否 | "Scrollbar" | 滚动条名称 |
| string | 否 | null | 父级对象 |
| string | 否 | "BottomToTop" | 滚动方向:LeftToRight/RightToLeft/BottomToTop/TopToBottom |
| float | 否 | 0 | 初始值(0-1) |
| float | 否 | 0.2 | 滑块尺寸(0-1) |
| int | 否 | 0 | 0=连续滚动,大于0为离散滚动 |
Property Configuration Skills
属性配置技能
ui_set_image
ui_set_image
Set Image advanced properties (type, fill, sprite).
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No* | — | Image element name |
| int | No* | 0 | Instance ID |
| string | No | — | Simple/Sliced/Tiled/Filled |
| string | No | — | Radial360/Radial180/Radial90/Horizontal/Vertical |
| float | No | — | 0-1 fill amount |
| bool | No | — | Fill direction |
| bool | No | — | Preserve aspect ratio |
| string | No | — | Sprite asset path |
设置Image的高级属性(类型、填充、精灵图)。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否* | — | Image元素名称 |
| int | 否* | 0 | 实例ID |
| string | 否 | — | 图片类型:Simple/Sliced/Tiled/Filled |
| string | 否 | — | 填充方式:Radial360/Radial180/Radial90/Horizontal/Vertical |
| float | 否 | — | 填充比例(0-1) |
| bool | 否 | — | 填充方向是否为顺时针 |
| bool | 否 | — | 是否保持宽高比 |
| string | 否 | — | 精灵图资源路径 |
ui_add_layout_element
ui_add_layout_element
Add/configure LayoutElement constraints.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No* | — | Element name |
| float | No | — | Minimum size |
| float | No | — | Preferred size |
| float | No | — | Flexible size (0=fixed, >0=grow) |
| bool | No | — | Ignore layout group |
| int | No | — | Priority (higher overrides) |
添加/配置LayoutElement约束。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否* | — | 元素名称 |
| float | 否 | — | 最小尺寸 |
| float | 否 | — | 首选尺寸 |
| float | 否 | — | 弹性尺寸(0=固定尺寸,大于0可拉伸) |
| bool | 否 | — | 是否忽略布局组规则 |
| int | 否 | — | 布局优先级(值越高优先级越高) |
ui_add_canvas_group
ui_add_canvas_group
Add/configure CanvasGroup (alpha, interactable, blocksRaycasts).
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No* | — | Element name |
| float | No | — | Group alpha (0-1) |
| bool | No | — | Children interactable |
| bool | No | — | Blocks raycasts |
| bool | No | — | Ignore parent groups |
添加/配置CanvasGroup(透明度、可交互性、射线检测阻挡)。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否* | — | 元素名称 |
| float | 否 | — | 组透明度(0-1) |
| bool | 否 | — | 子元素是否可交互 |
| bool | 否 | — | 是否阻挡射线检测 |
| bool | 否 | — | 是否忽略父级CanvasGroup规则 |
ui_add_mask
ui_add_mask
Add Mask (stencil-based) or RectMask2D (rect clipping).
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No* | — | Element name |
| string | No | "RectMask2D" | Mask/RectMask2D |
| bool | No | true | Show mask graphic (Mask only) |
添加Mask(基于模板缓冲)或RectMask2D(矩形裁剪)。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否* | — | 元素名称 |
| string | 否 | "RectMask2D" | 遮罩类型:Mask/RectMask2D |
| bool | 否 | true | 是否显示遮罩图形(仅Mask类型生效) |
ui_add_outline
ui_add_outline
Add Shadow or Outline visual effect.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No* | — | Element name |
| string | No | "Outline" | Shadow/Outline |
| float | No | 0,0,0,0.5 | Effect color |
| float | No | 1/-1 | Effect offset |
| bool | No | true | Use graphic alpha |
添加阴影或描边视觉效果。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否* | — | 元素名称 |
| string | 否 | "Outline" | 效果类型:Shadow/Outline |
| float | 否 | 0,0,0,0.5 | 效果颜色 |
| float | 否 | 1/-1 | 效果偏移 |
| bool | 否 | true | 是否使用图形透明度 |
ui_configure_selectable
ui_configure_selectable
Configure Selectable properties on Button/Toggle/Slider/etc.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No* | — | Element name |
| string | No | — | None/ColorTint/SpriteSwap/Animation |
| bool | No | — | Interactable state |
| string | No | — | None/Horizontal/Vertical/Automatic/Explicit |
| float | No | — | Normal state color |
| float | No | — | Highlighted state color |
| float | No | — | Pressed state color |
| float | No | — | Disabled state color |
| float | No | — | Color multiplier (1-5) |
| float | No | — | Fade duration |
配置Button/Toggle/Slider等可交互组件的属性。
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否* | — | 元素名称 |
| string | 否 | — | 过渡效果:None/ColorTint/SpriteSwap/Animation |
| bool | 否 | — | 可交互状态 |
| string | 否 | — | 导航模式:None/Horizontal/Vertical/Automatic/Explicit |
| float | 否 | — | 正常状态颜色 |
| float | 否 | — | 高亮状态颜色 |
| float | 否 | — | 按下状态颜色 |
| float | 否 | — | 禁用状态颜色 |
| float | 否 | — | 颜色倍数(1-5) |
| float | 否 | — | 淡入淡出时长 |
Best Practices
最佳实践
- Always create Canvas first
- Use Panels to organize related elements
- Use meaningful names for scripting access
- Set parent for proper hierarchy
- WorldSpace canvas for 3D UI (health bars, etc.)
- 始终优先创建Canvas
- 使用Panel组织相关联的元素
- 使用有意义的命名方便后续脚本访问
- 设置父元素以维护正确的层级关系
- 3D UI(如血条等)使用WorldSpace渲染模式的Canvas