unity-mcp/docs/i18n/README-zh.md

9.8 KiB
Raw Blame History

MCP for Unity
English 简体中文

Coplay 荣誉赞助并维护 —— Unity 最好的 AI 助手。

Discord Unity Asset Store python

用大语言模型创建你的 Unity 应用! MCP for Unity 通过 Model Context Protocol 将 AI 助手Claude、Cursor、VS Code 等)与你的 Unity Editor 连接起来。为你的大语言模型提供管理资源、控制场景、编辑脚本和自动化任务的工具。

MCP for Unity building a scene

快速开始

前置要求

1. 安装 Unity 包

在 Unity 中:Window > Package Manager > + > Add package from git URL...

[!TIP]

https://github.com/CoplayDev/unity-mcp.git?path=/MCPForUnity

想要最新的 beta 版本? 使用 beta 分支:

https://github.com/CoplayDev/unity-mcp.git?path=/MCPForUnity#beta
其他安装方式Asset Store、OpenUPM

Unity Asset Store

  1. 访问 Asset Store 上的 MCP for Unity
  2. 点击 Add to My Assets,然后通过 Window > Package Manager 导入

OpenUPM

openupm add com.coplaydev.unity-mcp

2. 启动服务器并连接

  1. 在 Unity 中:Window > MCP for Unity
  2. 点击 Start Server(会在 localhost:8080 启动 HTTP 服务器)
  3. 从下拉菜单选择你的 MCP Client然后点击 Configure
  4. 查找 🟢 "Connected ✓"
  5. 连接你的客户端: 一些客户端Cursor、Windsurf、Antigravity需要在设置里启用 MCP 开关另一些Claude Desktop、Claude Code在配置后会自动连接。

就这些! 试试这样的提示词:"Create a red, blue and yellow cube""Build a simple player controller"


功能与工具

关键功能

  • 自然语言控制 — 指示你的大语言模型执行 Unity 任务
  • 强大工具 — 管理资源、场景、材质、脚本和编辑器功能
  • 自动化 — 自动化重复的 Unity 工作流程
  • 可扩展 — 可与多种 MCP Client 配合使用

可用工具

manage_assetmanage_editormanage_gameobjectmanage_componentsmanage_materialmanage_prefabsmanage_scenemanage_scriptmanage_scriptable_objectmanage_shadermanage_vfxbatch_executefind_gameobjectsfind_in_fileread_consolerefresh_unityrun_testsget_test_jobexecute_menu_itemapply_text_editsscript_apply_editsvalidate_scriptcreate_scriptdelete_scriptget_sha

可用资源

custom_toolsunity_instancesmenu_itemsget_testsgameobjectgameobject_componentseditor_stateeditor_selectioneditor_prefab_stageproject_infoproject_tagsproject_layers

性能提示: 多个操作请使用 batch_execute — 比逐个调用快 10-100 倍!

手动配置

如果自动设置不生效,请把下面内容添加到你的 MCP Client 配置文件中:

HTTP默认 — 适用于 Claude Desktop、Cursor、Windsurf

{
  "mcpServers": {
    "unityMCP": {
      "url": "http://localhost:8080/mcp"
    }
  }
}

VS Code

{
  "servers": {
    "unityMCP": {
      "type": "http",
      "url": "http://localhost:8080/mcp"
    }
  }
}
Stdio 配置(旧版)

macOS/Linux

{
  "mcpServers": {
    "unityMCP": {
      "command": "uv",
      "args": ["run", "--directory", "/Users/YOUR_USERNAME/Library/AppSupport/UnityMCP/UnityMcpServer/src", "server.py", "--transport", "stdio"]
    }
  }
}

Windows

{
  "mcpServers": {
    "unityMCP": {
      "command": "C:/Users/YOUR_USERNAME/AppData/Local/Microsoft/WinGet/Links/uv.exe",
      "args": ["run", "--directory", "C:/Users/YOUR_USERNAME/AppData/Local/UnityMCP/UnityMcpServer/src", "server.py", "--transport", "stdio"]
    }
  }
}
多个 Unity 实例

MCP for Unity 支持多个 Unity Editor 实例。要将操作定向到某个特定实例:

  1. 让你的大语言模型检查 unity_instances 资源
  2. 使用 set_active_instance 并传入 Name@hash(例如 MyProject@abc123
  3. 后续所有工具都会路由到该实例
Roslyn 脚本验证(高级)

要使用能捕获未定义命名空间、类型和方法的 Strict 验证:

  1. 安装 NuGetForUnity
  2. Window > NuGet Package Manager → 安装 Microsoft.CodeAnalysis v4.14.0
  3. 同时安装 SQLitePCLRaw.coreSQLitePCLRaw.bundle_e_sqlite3
  4. Player Settings > Scripting Define Symbols 中添加 USE_ROSLYN
  5. 重启 Unity
手动 DLL 安装(如果 NuGetForUnity 不可用)
  1. NuGet 下载 Microsoft.CodeAnalysis.CSharp.dll 及其依赖项
  2. 将 DLL 放到 Assets/Plugins/ 目录
  3. 确保 .NET 兼容性设置正确
  4. 在 Scripting Define Symbols 中添加 USE_ROSLYN
  5. 重启 Unity
故障排除
  • Unity Bridge 无法连接: 检查 Window > MCP for Unity 状态,重启 Unity
  • Server 无法启动: 确认 uv --version 可用,并检查终端错误
  • Client 无法连接: 确认 HTTP server 正在运行,并且 URL 与你的配置一致

详细的设置指南:

还是卡住?开一个 Issue加入 Discord

贡献

开发环境设置见 README-DEV.md。自定义工具见 CUSTOM_TOOLS.md

  1. Fork → 创建 issue → 新建分支(feature/your-idea)→ 修改 → 提 PR
遥测与隐私

匿名、注重隐私的遥测(不包含代码、项目名或个人数据)。可通过 DISABLE_TELEMETRY=true 关闭。详见 TELEMETRY.md


许可证: MIT — 查看 LICENSE | 需要帮助? Discord | Issues


Star 历史

Star History Chart

研究引用 如果你正在进行与 Unity-MCP 相关的研究,请引用我们!
@inproceedings{10.1145/3757376.3771417,
author = {Wu, Shutong and Barnett, Justin P.},
title = {MCP-Unity: Protocol-Driven Framework for Interactive 3D Authoring},
year = {2025},
isbn = {9798400721366},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
url = {https://doi.org/10.1145/3757376.3771417},
doi = {10.1145/3757376.3771417},
series = {SA Technical Communications '25}
}

Coplay 的 Unity AI 工具

Coplay 提供 3 个 Unity AI 工具:

  • MCP for Unity 在 MIT 许可证下免费提供。
  • Coplay 是一个运行在 Unity 内的高级 Unity AI 助手,功能超过 MCP for Unity。
  • Coplay MCP 是 Coplay 工具的“目前免费”版 MCP。

(这些工具有不同的技术栈。参见这篇博客文章:comparing Coplay to MCP for Unity。)

Coplay

免责声明

本项目是一个免费开源的 Unity Editor 工具,与 Unity Technologies 无关。