Unity 插件:AI 驱动的游戏开发 - Openclaw Skills

作者:互联网

2026-03-26

其他

什么是 Unity 插件技能?

Unity 插件技能是 AI 编码智能体与 Unity 引擎之间的强大桥梁,为专业游戏开发提供约 100 种内置工具。通过利用 Openclaw Skills,开发者可以赋能其 AI 智能体执行复杂的编辑器任务、管理项目资产并以编程方式控制运行模式。该集成支持两种主要的连接模式:用于 Discord 或 Telegram 等频道的远程网关,以及用于与 Claude Code 和 Cursor 等 IDE 集成的本地 MCP 桥接器。它旨在通过自动化层级导航、组件调整和重复测试周期等手动繁琐工作,最大限度地提高开发者生产力。

下载入口:https://github.com/openclaw/skills/tree/main/skills/tomleelive/openclaw-unity-skill

安装与下载

1. ClawHub CLI

从源直接安装技能的最快方式。

npx clawhub@latest install openclaw-unity-skill

2. 手动安装

将技能文件夹复制到以下位置之一

全局模式 ~/.openclaw/skills/ 工作区 /skills/

优先级:工作区 > 本地 > 内置

3. 提示词安装

将此提示词复制到 OpenClaw 即可自动安装。

请帮我使用 Clawhub 安装 openclaw-unity-skill。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。

Unity 插件技能 应用场景

  • 自动化场景检查和层级数据检索。
  • 通过自然语言修改 GameObject 的变换、组件和材质。
  • 模拟用户输入并截取屏幕快照以进行自动化 UI 测试。
  • 无需手动导航即可管理项目资产、预制件和包。
  • 使用 Openclaw Skills 批量处理复杂的编辑器操作以加速开发周期。
Unity 插件技能 工作原理
  1. 使用远程网关扩展或本地 MCP 桥接器将 Unity 编辑器连接到 OpenClaw 环境。
  2. AI 智能体调用 unity_execute 工具或访问 MCP 资源 URI 向编辑器发送指令。
  3. Unity 插件接收命令并与 Unity API 交互以操作 GameObject、资产或编辑器状态。
  4. 实时反馈、日志或视觉数据(如截图)将返回给 AI 智能体,以确认操作成功。
  5. 开发者可以通过 Unity 编辑器内的 OpenClaw 插件设置窗口监控交互过程。

Unity 插件技能 配置指南

要为 Openclaw Skills 安装网关扩展,请在技能目录下运行以下命令:

./scripts/install-extension.sh
openclaw gateway restart

对于与 Claude Code 等工具的本地 MCP 集成,请在 Unity 中启动 MCP 桥接器(Window -> OpenClaw Plugin -> MCP Bridge -> Start)并注册服务器:

claude mcp add unity -- node /MCP~/index.js

Unity 插件技能 数据架构与分类体系

该技能将数据组织为几个逻辑类别,为 Openclaw Skills 智能体提供清晰的接口:

类别 描述
场景数据 完整的层级结构快照和活动场景元数据。
变换 空间数据,包括世界坐标、欧拉角旋转和局部缩放。
资产 项目视图中预制件、材质、着色器和纹理的元数据。
控制台 实时捕捉来自 Unity 控制台的日志、警告和错误消息。
资源 用于直接数据访问的专用 MCP URI(例如 unity://scene/hierarchy)。
name: unity-plugin
version: 1.6.1
description: Control Unity Editor via OpenClaw Unity Plugin. Use for Unity game development tasks including scene management, GameObject/Component manipulation, debugging, input simulation, and Play mode control. Triggers on Unity-related requests like inspecting scenes, creating objects, taking screenshots, testing gameplay, or controlling the Editor.
homepage: https://github.com/TomLeeLive/openclaw-unity-skill
author: Tom Jaejoon Lee
disableModelInvocation: true

Unity Plugin Skill

Control Unity Editor through ~100 built-in tools. Works in both Editor and Play mode.

Connection Modes

1. OpenClaw Gateway (Remote)

For Telegram, Discord, and other OpenClaw channels:

  • Auto-connects when Unity opens
  • Configure in: Window → OpenClaw Plugin → Settings

2. MCP Bridge (Local)

For Claude Code, Cursor, and local AI tools:

  • Start: Window → OpenClaw Plugin → MCP Bridge → Start
  • Default port: 27182
  • Add to Claude Code: claude mcp add unity -- node /MCP~/index.js

First-Time Setup

If unity_execute tool is not available, install the gateway extension:

# From skill directory
./scripts/install-extension.sh

# Restart gateway
openclaw gateway restart

The extension files are in extension/ directory.

What install-extension.sh Does

# 1. Copies extension files from skill to gateway
#    Source: /extension/
#    Destination: ~/.openclaw/extensions/unity/

# 2. Files installed:
#    - index.ts     # Extension entry point (HTTP handlers, tools)
#    - package.json # Extension metadata

# After installation, restart gateway to load the extension.

?? Security

? ??? disableModelInvocation: true? ???? ????.

  • AI? ???? ??? ???? ??
  • ???? ????? ??? ??? ??

?? ?? ??? README.md? ?????.

Quick Reference

Core Tools

Category Key Tools
Scene scene.getActive, scene.getData, scene.load, scene.open, scene.save
GameObject gameobject.find, gameobject.getAll, gameobject.create, gameobject.destroy
Component component.get, component.set, component.add, component.remove
Transform transform.setPosition, transform.setRotation, transform.setScale
Debug debug.hierarchy, debug.screenshot, console.getLogs
Input input.clickUI, input.type, input.keyPress, input.mouseClick
Editor editor.getState, editor.play, editor.stop, editor.refresh
Material material.create, material.assign, material.modify, material.getInfo
Prefab prefab.create, prefab.instantiate, prefab.open, prefab.save
Asset asset.find, asset.copy, asset.move, asset.delete
Package package.add, package.remove, package.list, package.search
Test test.run, test.list, test.getResults

Common Workflows

1. Scene Inspection

unity_execute: debug.hierarchy {depth: 2}
unity_execute: scene.getActive

2. Find & Modify Objects

unity_execute: gameobject.find {name: "Player"}
unity_execute: component.get {name: "Player", componentType: "Transform"}
unity_execute: transform.setPosition {name: "Player", x: 0, y: 5, z: 0}

3. UI Testing

unity_execute: input.clickUI {name: "PlayButton"}
unity_execute: input.type {text: "TestUser", elementName: "UsernameInput"}
unity_execute: debug.screenshot

4. Play Mode Control

unity_execute: editor.play              # Enter Play mode
unity_execute: editor.stop              # Exit Play mode
unity_execute: editor.getState          # Check current state
unity_execute: editor.pause             # Pause
unity_execute: editor.unpause           # Resume

5. Material Creation

unity_execute: material.create {name: "RedMetal", color: "#FF0000", metallic: 0.8}
unity_execute: material.assign {gameObjectName: "Player", materialPath: "Assets/Materials/RedMetal.mat"}
unity_execute: material.modify {path: "Assets/Materials/RedMetal.mat", metallic: 1.0, emission: "#FF4444"}

6. Prefab Workflow

unity_execute: prefab.create {gameObjectName: "Player", path: "Assets/Prefabs/Player.prefab"}
unity_execute: prefab.instantiate {prefabPath: "Assets/Prefabs/Player.prefab", x: 0, y: 1, z: 0}
unity_execute: prefab.open {path: "Assets/Prefabs/Player.prefab"}
unity_execute: prefab.save
unity_execute: prefab.close

7. Asset Management

unity_execute: asset.find {query: "Player", type: "Prefab"}
unity_execute: asset.copy {sourcePath: "Assets/Prefabs/Player.prefab", destPath: "Assets/Backup/Player.prefab"}
unity_execute: asset.move {sourcePath: "Assets/Old/Item.prefab", destPath: "Assets/New/Item.prefab"}

8. Package Management

unity_execute: package.list
unity_execute: package.search {query: "TextMeshPro"}
unity_execute: package.add {packageName: "com.unity.textmeshpro"}
unity_execute: package.add {gitUrl: "https://github.com/example/package.git"}

9. Test Running

unity_execute: test.list {testMode: "EditMode"}
unity_execute: test.run {testMode: "EditMode", filter: "PlayerTests"}
unity_execute: test.getResults

10. Script Execution (Enhanced)

# Debug logging
unity_execute: script.execute {code: "Debug.Log('Hello')"}

# Time manipulation
unity_execute: script.execute {code: "Time.timeScale = 0.5"}

# PlayerPrefs
unity_execute: script.execute {code: "PlayerPrefs.SetInt('score', 100)"}

# Reflection-based method calls
unity_execute: script.execute {code: "MyClass.MyMethod()"}
unity_execute: script.execute {code: "MyClass.MyStaticMethod('param1', 123)"}

Tool Categories (~100 tools)

Console (3 tools)

  • console.getLogs - Get logs with optional type filter (Log/Warning/Error)
  • console.getErrors - Get error/exception logs (with optional warnings)
  • console.clear - Clear captured logs

Scene (7 tools)

  • scene.list - List scenes in build settings
  • scene.getActive - Get active scene info
  • scene.getData - Get full hierarchy data
  • scene.load - Load scene by name (Play mode)
  • scene.open - Open scene in Editor mode
  • scene.save - Save active scene (Editor mode)
  • scene.saveAll - Save all open scenes (Editor mode)

GameObject (8 tools)

  • gameobject.find - Find by name, tag, or component
  • gameobject.getAll - Get all GameObjects with filtering
  • gameobject.create - Create object or primitive (Cube, Sphere, etc.)
  • gameobject.destroy - Destroy object
  • gameobject.delete - Delete object (alias for destroy)
  • gameobject.getData - Get detailed data
  • gameobject.setActive - Enable/disable
  • gameobject.setParent - Change hierarchy

Transform (6 tools)

  • transform.getPosition - Get world position {x, y, z}
  • transform.getRotation - Get Euler rotation {x, y, z}
  • transform.getScale - Get local scale {x, y, z}
  • transform.setPosition - Set world position {x, y, z}
  • transform.setRotation - Set Euler rotation
  • transform.setScale - Set local scale

Component (5 tools)

  • component.add - Add component by type name
  • component.remove - Remove component
  • component.get - Get component data/properties
  • component.set - Set field/property value
  • component.list - List available component types

Script (3 tools)

  • script.execute - Execute code: Debug.Log, Time, PlayerPrefs, reflection calls
  • script.read - Read script file
  • script.list - List project scripts

Application (4 tools)

  • app.getState - Get play mode, FPS, time
  • app.play - Enter/exit Play mode
  • app.pause - Toggle pause
  • app.stop - Stop Play mode

Debug (3 tools)

  • debug.log - Write to console
  • debug.screenshot - Capture screenshot
  • debug.hierarchy - Text hierarchy view

Editor (9 tools)

  • editor.refresh - Refresh AssetDatabase (triggers recompile)
  • editor.recompile - Request script recompilation
  • editor.domainReload - Force domain reload
  • editor.focusWindow - Focus window (game/scene/console/hierarchy/project/inspector)
  • editor.listWindows - List open windows
  • editor.getState - Get editor state
  • editor.play - Enter Play mode
  • editor.stop - Exit Play mode
  • editor.pause / editor.unpause - Pause control

Input Simulation (10 tools)

  • input.keyPress - Press and release key
  • input.keyDown / input.keyUp - Hold/release key
  • input.type - Type text into field
  • input.mouseMove - Move cursor
  • input.mouseClick - Click at position
  • input.mouseDrag - Drag operation
  • input.mouseScroll - Scroll wheel
  • input.getMousePosition - Get cursor position
  • input.clickUI - Click UI element by name

Material (5 tools) - NEW in v1.5.0

  • material.create - Create material with shader, color, metallic, smoothness
  • material.assign - Assign material to GameObject
  • material.modify - Modify material properties (color, metallic, emission)
  • material.getInfo - Get detailed material info with all shader properties
  • material.list - List materials in project with filtering

Prefab (5 tools) - NEW in v1.5.0

  • prefab.create - Create prefab from scene GameObject
  • prefab.instantiate - Instantiate prefab in scene with position
  • prefab.open - Open prefab for editing
  • prefab.close - Close prefab editing mode
  • prefab.save - Save currently edited prefab

Asset (7 tools) - NEW in v1.5.0

  • asset.find - Search assets by query, type, folder
  • asset.copy - Copy asset to new path
  • asset.move - Move/rename asset
  • asset.delete - Delete asset (with trash option)
  • asset.refresh - Refresh AssetDatabase
  • asset.import - Import/reimport specific asset
  • asset.getPath - Get asset path by name

Package Manager (4 tools) - NEW in v1.5.0

  • package.add - Install package by name or git URL
  • package.remove - Remove installed package
  • package.list - List installed packages
  • package.search - Search Unity package registry

Test Runner (3 tools) - NEW in v1.5.0

  • test.run - Run EditMode/PlayMode tests with filtering
  • test.list - List available tests
  • test.getResults - Get last test run results

Batch Execution (1 tool) - NEW in v1.6.0

  • batch.execute - Execute multiple tools in one call (10-100x performance)
    • commands: Array of {tool, params} objects
    • stopOnError: Stop on first error (default: false)

Session (1 tool) - NEW in v1.6.0

  • session.getInfo - Get session info (project, processId, machineName, sessionId)

ScriptableObject (6 tools) - NEW in v1.6.0

  • scriptableobject.create - Create new ScriptableObject asset
  • scriptableobject.load - Load and inspect ScriptableObject fields
  • scriptableobject.save - Save ScriptableObject changes
  • scriptableobject.getField - Get specific field value
  • scriptableobject.setField - Set field value with auto-save
  • scriptableobject.list - List ScriptableObjects in project

Shader (3 tools) - NEW in v1.6.0

  • shader.list - List shaders in project
  • shader.getInfo - Get shader properties and info
  • shader.getKeywords - Get shader keywords

Texture (5 tools) - NEW in v1.6.0

  • texture.create - Create new texture with color fill
  • texture.getInfo - Get texture info (size, format, import settings)
  • texture.setPixels - Fill region with color
  • texture.resize - Resize texture via import settings
  • texture.list - List textures in project

Custom Tools API - v1.6.0

Register project-specific tools:

OpenClawCustomTools.Register(
    "mygame.getScore",
    "Get current score",
    (args) => new { success = true, score = GameManager.Score }
);

MCP Resources - v1.6.0

Access Unity data via MCP resource URIs:

URI Description
unity://scene/hierarchy Scene hierarchy
unity://scene/active Active scene info
unity://project/scripts Script list
unity://project/scenes Scene list
unity://editor/state Editor state
unity://console/logs Console logs
unity://session/info Session info

Tips

Screenshot Modes

  • Play mode: ScreenCapture - includes all UI overlays
  • Editor mode: Camera.main.Render() - no overlay UI
  • Use {method: "camera"} for camera-only capture

Finding Objects

gameobject.find {name: "Player"}           # By exact name
gameobject.find {tag: "Enemy"}             # By tag
gameobject.find {componentType: "Camera"}  # By component
gameobject.getAll {activeOnly: true}       # All active objects

Script Recompilation

Unity may not auto-recompile after code changes. Use:

editor.refresh    # Full asset refresh + recompile

Play Mode Transitions

  • Plugin survives Play mode transitions via SessionState
  • If connection lost, wait for auto-reconnect or use Window → OpenClaw Plugin → Settings → Connect

MCP Bridge Usage

For Claude Code / Cursor integration:

  1. Start: Window → OpenClaw Plugin → MCP Bridge → Start
  2. Register: claude mcp add unity -- node /path/to/MCP~/index.js
  3. Verify: curl http://127.0.0.1:27182/status

Input Simulation Limitation

Keyboard/mouse simulation works for UI interactions but NOT for Input.GetKey(). For gameplay testing:

  • Use transform.setPosition to move objects directly
  • Or migrate to Unity's new Input System

Troubleshooting

Issue Solution
Tool timeout Check Unity is responding, try editor.getState
Gateway no connection Check Window → OpenClaw Plugin → Settings
MCP no connection Start MCP Bridge, verify port 27182
Scripts not updating Use editor.refresh to force recompile
Wrong screenshot Use Play mode for game view with UI
MCP 504 timeout Unity busy or MCP Bridge not started
Test Runner not found Install com.unity.test-framework package
  • Skill Repository: https://github.com/TomLeeLive/openclaw-unity-skill
  • Plugin Repository: https://github.com/TomLeeLive/openclaw-unity-plugin
  • OpenClaw Docs: https://docs.openclaw.ai
  • MCP Setup Guide: See Plugin Repository → Documentation~/SETUP_GUIDE.md

License

MIT License - See LICENSE file