unity-component
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUnity Component Skills
Unity 组件技能
BATCH-FIRST: Useskills when operating on 2+ objects to reduce API calls from N to 1.*_batch
优先批量操作:当操作2个及以上对象时,使用技能,可将API调用次数从N次减少到1次。*_batch
Guardrails
约束规则
Mode: Full-Auto required
DO NOT (common hallucinations):
- /
component_createdo not exist → usecomponent_get(add) andcomponent_add(read)component_get_properties - does not exist → use
component_findto list components on an objectcomponent_list - is case-sensitive —
componentTypenotRigidbody,rigidbodynotBoxColliderboxcollider - Custom scripts need exact class name; if namespaced, use
Namespace.ClassName
Routing:
- To create a C# component script → use module's
scriptfirst, thenscript_createcomponent_add - To set multiple properties at once → use
component_set_property_batch - To enable/disable a component → (not
component_set_enabled)component_set_property
Object Targeting: All single-object skills accept(string),name(int, preferred), andinstanceId(string, hierarchy path). Provide at least one.path
模式:需设置为全自动模式
禁止操作(常见错误):
- 不存在/
component_create→ 使用component_get(添加)和component_add(读取)component_get_properties - 不存在→ 使用
component_find列出对象上的所有组件component_list - 区分大小写 — 需写
componentType而非Rigidbody,rigidbody而非BoxColliderboxcollider - 自定义脚本需使用精确类名;若包含命名空间,使用格式
Namespace.ClassName
路由指引:
- 若要创建C#组件脚本 → 先使用模块的
script,再调用script_createcomponent_add - 若要一次性设置多个属性 → 使用
component_set_property_batch - 若要启用/禁用组件 → 使用(而非
component_set_enabled)component_set_property
对象定位:所有单对象技能支持(字符串)、name(整数,推荐使用)和instanceId(字符串,层级路径)作为参数。至少需提供其中一个。path
Skills Overview
技能概览
| Single Object | Batch Version | Use Batch When |
|---|---|---|
| | Adding to 2+ objects |
| | Removing from 2+ objects |
| | Setting on 2+ objects |
Other Skills (no batch):
- - List all components on an object
component_list - - Get component property values
component_get_properties - - Enable/disable a component (Behaviour, Renderer, Collider)
component_set_enabled - - Copy a component from one object to another
component_copy
| 单对象技能 | 批量版本 | 何时使用批量版本 |
|---|---|---|
| | 给2个及以上对象添加组件时 |
| | 从2个及以上对象移除组件时 |
| | 给2个及以上对象设置属性时 |
其他技能(无批量版本):
- - 列出对象上的所有组件
component_list - - 获取组件的属性值
component_get_properties - - 启用/禁用组件(Behaviour、Renderer、Collider类型)
component_set_enabled - - 将组件从一个对象复制到另一个对象
component_copy
Single-Object Skills
单对象技能
component_add
component_add
Add a component to a GameObject.
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | No* | GameObject name |
| int | No* | Instance ID (preferred) |
| string | No* | Hierarchy path |
| string | Yes | Component type name |
*At least one identifier required
Returns:
{success, gameObject, componentType, added}给GameObject添加组件。
| 参数 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| string | 否* | GameObject名称 |
| int | 否* | 实例ID(推荐使用) |
| string | 否* | 层级路径 |
| string | 是 | 组件类型名称 |
*至少需提供一个标识符
返回值:
{success, gameObject, componentType, added}component_remove
component_remove
Remove a component from a GameObject.
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | No* | GameObject name |
| int | No* | Instance ID |
| string | Yes | Component type to remove |
Returns:
{success, gameObject, componentType, removed}从GameObject移除组件。
| 参数 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| string | 否* | GameObject名称 |
| int | 否* | 实例ID |
| string | 是 | 要移除的组件类型 |
返回值:
{success, gameObject, componentType, removed}component_list
component_list
List all components on a GameObject.
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | No* | GameObject name |
| int | No* | Instance ID |
Returns:
{success, gameObject, instanceId, components: [string]}列出GameObject上的所有组件。
| 参数 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| string | 否* | GameObject名称 |
| int | 否* | 实例ID |
返回值:
{success, gameObject, instanceId, components: [string]}component_set_property
component_set_property
Set a component property value.
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | No* | GameObject name |
| int | No* | Instance ID |
| string | Yes | Component type |
| string | Yes | Property to set |
| any | Cond. | New value (for basic types, vectors, colors) |
| string | No | Scene object hierarchy path (for scene references) |
| string | No | Scene object name (for scene references) |
| string | No | Project asset path (for asset references: Material, Texture, AudioClip, ScriptableObject, Prefab, etc.) |
Provide one of:(basic types),value/referencePath(scene objects), orreferenceName(project assets).assetPath
valuepython
undefined设置组件的属性值。
| 参数 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| string | 否* | GameObject名称 |
| int | 否* | 实例ID |
| string | 是 | 组件类型 |
| string | 是 | 要设置的属性名称 |
| any | 可选 | 新值(支持基本类型、向量、颜色) |
| string | 否 | 场景对象层级路径(用于场景引用) |
| string | 否 | 场景对象名称(用于场景引用) |
| string | 否 | 项目资源路径(用于资源引用:Material、Texture、AudioClip、ScriptableObject、Prefab等) |
需提供以下其中一种:(基本类型)、value/referencePath(场景对象)、referenceName(项目资源)。assetPath
valuepython
undefinedfloat / int / bool / string
float / int / bool / string
call_skill("component_set_property", name="Obj", componentType="Rigidbody", propertyName="mass", value=2.5)
call_skill("component_set_property", name="Obj", componentType="Rigidbody", propertyName="useGravity", value=False)
call_skill("component_set_property", name="Obj", componentType="Rigidbody", propertyName="mass", value=2.5)
call_skill("component_set_property", name="Obj", componentType="Rigidbody", propertyName="useGravity", value=False)
Vector3 (JSON object with x, y, z)
Vector3(包含x、y、z的JSON对象)
call_skill("component_set_property", name="Obj", componentType="Transform", propertyName="localPosition",
value={"x": 1, "y": 2, "z": 3})
call_skill("component_set_property", name="Obj", componentType="Transform", propertyName="localPosition",
value={"x": 1, "y": 2, "z": 3})
Color (JSON object with r, g, b, a — values 0-1)
Color(包含r、g、b、a的JSON对象,值范围0-1)
call_skill("component_set_property", name="Obj", componentType="Light", propertyName="color",
value={"r": 1, "g": 0.5, "b": 0, "a": 1})
call_skill("component_set_property", name="Obj", componentType="Light", propertyName="color",
value={"r": 1, "g": 0.5, "b": 0, "a": 1})
Enum (use string name)
枚举(使用字符串名称)
call_skill("component_set_property", name="Obj", componentType="Rigidbody", propertyName="interpolation",
value="Interpolate")
**Returns**: `{success, gameObject, componentType, property, oldValue, newValue}`call_skill("component_set_property", name="Obj", componentType="Rigidbody", propertyName="interpolation",
value="Interpolate")
**返回值**:`{success, gameObject, componentType, property, oldValue, newValue}`component_get_properties
component_get_properties
Get all properties of a component.
| Parameter | Type | Required | Description |
|---|---|---|---|
| string | No* | GameObject name |
| int | No* | Instance ID |
| string | Yes | Component type |
Returns:
{success, gameObject, componentType, properties: {name: value}}获取组件的所有属性。
| 参数 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| string | 否* | GameObject名称 |
| int | 否* | 实例ID |
| string | 是 | 组件类型 |
返回值:
{success, gameObject, componentType, properties: {name: value}}Batch Skills
批量技能
component_add_batch
component_add_batch
Add components to multiple objects.
Returns:
{success, totalItems, successCount, failCount, results: [{success, gameObject, componentType, added}]}python
unity_skills.call_skill("component_add_batch", items=[
{"name": "Enemy1", "componentType": "Rigidbody"},
{"name": "Enemy2", "componentType": "Rigidbody"},
{"name": "Enemy3", "componentType": "Rigidbody"}
])给多个对象添加组件。
返回值:
{success, totalItems, successCount, failCount, results: [{success, gameObject, componentType, added}]}python
unity_skills.call_skill("component_add_batch", items=[
{"name": "Enemy1", "componentType": "Rigidbody"},
{"name": "Enemy2", "componentType": "Rigidbody"},
{"name": "Enemy3", "componentType": "Rigidbody"}
])component_remove_batch
component_remove_batch
Remove components from multiple objects.
Returns:
{success, totalItems, successCount, failCount, results: [{success, gameObject, componentType, removed}]}python
unity_skills.call_skill("component_remove_batch", items=[
{"instanceId": 12345, "componentType": "BoxCollider"},
{"instanceId": 12346, "componentType": "BoxCollider"}
])从多个对象移除组件。
返回值:
{success, totalItems, successCount, failCount, results: [{success, gameObject, componentType, removed}]}python
unity_skills.call_skill("component_remove_batch", items=[
{"instanceId": 12345, "componentType": "BoxCollider"},
{"instanceId": 12346, "componentType": "BoxCollider"}
])component_set_property_batch
component_set_property_batch
Set properties on multiple objects.
Returns:
{success, totalItems, successCount, failCount, results: [{success, gameObject, componentType, property, oldValue, newValue}]}python
unity_skills.call_skill("component_set_property_batch", items=[
{"name": "Enemy1", "componentType": "Rigidbody", "propertyName": "mass", "value": 2.0},
{"name": "Enemy2", "componentType": "Rigidbody", "propertyName": "mass", "value": 2.0}
])给多个对象设置属性。
返回值:
{success, totalItems, successCount, failCount, results: [{success, gameObject, componentType, property, oldValue, newValue}]}python
unity_skills.call_skill("component_set_property_batch", items=[
{"name": "Enemy1", "componentType": "Rigidbody", "propertyName": "mass", "value": 2.0},
{"name": "Enemy2", "componentType": "Rigidbody", "propertyName": "mass", "value": 2.0}
])Common Component Types
常见组件类型
Physics
物理类
| Type | Description |
|---|---|
| Physics simulation |
| Box collision |
| Sphere collision |
| Capsule collision |
| Mesh-based collision |
| Character movement |
| 类型 | 描述 |
|---|---|
| 物理模拟 |
| 盒型碰撞体 |
| 球形碰撞体 |
| 胶囊型碰撞体 |
| 基于网格的碰撞体 |
| 角色移动控制 |
Rendering
渲染类
| Type | Description |
|---|---|
| Render meshes |
| Animated meshes |
| 2D sprites |
| Draw lines |
| Motion trails |
| 类型 | 描述 |
|---|---|
| 渲染网格 |
| 渲染带动画的网格 |
| 渲染2D精灵 |
| 绘制线条 |
| 绘制运动轨迹 |
Audio
音频类
| Type | Description |
|---|---|
| Play sounds |
| Receive audio |
| 类型 | 描述 |
|---|---|
| 播放声音 |
| 接收音频 |
UI
UI类
| Type | Description |
|---|---|
| UI container |
| UI images |
| UI text (legacy) |
| Clickable button |
| 类型 | 描述 |
|---|---|
| UI容器 |
| UI图片 |
| UI文本(旧版) |
| 可点击按钮 |
Example: Efficient Physics Setup
示例:高效物理设置
python
import unity_skillspython
import unity_skillsBAD: 6 API calls
不推荐:6次API调用
unity_skills.call_skill("component_add", name="Box1", componentType="Rigidbody")
unity_skills.call_skill("component_add", name="Box2", componentType="Rigidbody")
unity_skills.call_skill("component_add", name="Box3", componentType="Rigidbody")
unity_skills.call_skill("component_set_property", name="Box1", componentType="Rigidbody", propertyName="mass", value=2.0)
unity_skills.call_skill("component_set_property", name="Box2", componentType="Rigidbody", propertyName="mass", value=2.0)
unity_skills.call_skill("component_set_property", name="Box3", componentType="Rigidbody", propertyName="mass", value=2.0)
unity_skills.call_skill("component_add", name="Box1", componentType="Rigidbody")
unity_skills.call_skill("component_add", name="Box2", componentType="Rigidbody")
unity_skills.call_skill("component_add", name="Box3", componentType="Rigidbody")
unity_skills.call_skill("component_set_property", name="Box1", componentType="Rigidbody", propertyName="mass", value=2.0)
unity_skills.call_skill("component_set_property", name="Box2", componentType="Rigidbody", propertyName="mass", value=2.0)
unity_skills.call_skill("component_set_property", name="Box3", componentType="Rigidbody", propertyName="mass", value=2.0)
GOOD: 2 API calls
推荐:2次API调用
unity_skills.call_skill("component_add_batch", items=[
{"name": "Box1", "componentType": "Rigidbody"},
{"name": "Box2", "componentType": "Rigidbody"},
{"name": "Box3", "componentType": "Rigidbody"}
])
unity_skills.call_skill("component_set_property_batch", items=[
{"name": "Box1", "componentType": "Rigidbody", "propertyName": "mass", "value": 2.0},
{"name": "Box2", "componentType": "Rigidbody", "propertyName": "mass", "value": 2.0},
{"name": "Box3", "componentType": "Rigidbody", "propertyName": "mass", "value": 2.0}
])
undefinedunity_skills.call_skill("component_add_batch", items=[
{"name": "Box1", "componentType": "Rigidbody"},
{"name": "Box2", "componentType": "Rigidbody"},
{"name": "Box3", "componentType": "Rigidbody"}
])
unity_skills.call_skill("component_set_property_batch", items=[
{"name": "Box1", "componentType": "Rigidbody", "propertyName": "mass", value=2.0},
{"name": "Box2", "componentType": "Rigidbody", "propertyName": "mass", value=2.0},
{"name": "Box3", "componentType": "Rigidbody", "propertyName": "mass", value=2.0}
])
undefinedBest Practices
最佳实践
- Add colliders before Rigidbody for physics
- Use to verify additions
component_list - Check property names with first
component_get_properties - Some properties are read-only (will fail to set)
- Use full type names for custom scripts (e.g., "MyNamespace.MyScript")
- 为物理组件添加碰撞体时,先添加Collider再添加Rigidbody
- 使用验证组件是否添加成功
component_list - 设置属性前,先用确认属性名称
component_get_properties - 部分属性为只读(设置会失败)
- 自定义脚本需使用完整类型名(例如:"MyNamespace.MyScript")
Additional Skills
额外技能
component_copy
component_copycomponent_copy
component_copyCopy a component from one GameObject to another.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No* | null | Source GameObject name |
| int | No* | 0 | Source Instance ID |
| string | No* | null | Source hierarchy path |
| string | No* | null | Target GameObject name |
| int | No* | 0 | Target Instance ID |
| string | No* | null | Target hierarchy path |
| string | Yes | - | Component type to copy |
*At least one source identifier and one target identifier required
Returns:
{ success, source, target, componentType }将组件从一个GameObject复制到另一个GameObject。
| 参数 | 类型 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否* | null | 源GameObject名称 |
| int | 否* | 0 | 源实例ID |
| string | 否* | null | 源层级路径 |
| string | 否* | null | 目标GameObject名称 |
| int | 否* | 0 | 目标实例ID |
| string | 否* | null | 目标层级路径 |
| string | 是 | - | 要复制的组件类型 |
*至少需提供一个源标识符和一个目标标识符
返回值:
{ success, source, target, componentType }component_set_enabled
component_set_enabledcomponent_set_enabled
component_set_enabledEnable or disable a component (Behaviour, Renderer, Collider, etc.).
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | No* | null | GameObject name |
| int | No* | 0 | Instance ID |
| string | No* | null | Hierarchy path |
| string | Yes | - | Component type to enable/disable |
| bool | No | true | Whether to enable or disable |
*At least one identifier required
Returns:
{ success, gameObject, componentType, enabled }启用或禁用组件(Behaviour、Renderer、Collider等类型)。
| 参数 | 类型 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|---|
| string | 否* | null | GameObject名称 |
| int | 否* | 0 | 实例ID |
| string | 否* | null | 层级路径 |
| string | 是 | - | 要启用/禁用的组件类型 |
| bool | 否 | true | 是否启用组件 |
*至少需提供一个标识符
返回值:
{ success, gameObject, componentType, enabled }Exact Signatures
精确签名
Exact names, parameters, defaults, and returns are defined by or , not by this file.
GET /skills/schemaunity_skills.get_skill_schema()精确的名称、参数、默认值和返回值由或定义,而非本文档。
GET /skills/schemaunity_skills.get_skill_schema()