🚀 知识与技能库(技能与MCP)
使用人工智能(反重力和统一MCP)自动化Unity编辑器的全球基础设施
🔌 统一Unity MCP服务器
我们优化的模型上下文协议服务器,提供对AI聊天中Unity对象的直接、安全和严格类型控制。
⚙️ 反重力配置
要将AI聊天客户端连接到正在运行的Unity编辑器,请添加以下配置:
{
"mcpServers": {
"unityMCP": {
"type": "sse",
"serverUrl": "http://127.0.0.1:18008/mcp",
"disabled": false,
"alwaysAllow": [],
"disabledTools": []
}
}
}服务器提供 52+工具 几乎涵盖了Unity的各个方面:
unity_gameobject,unity_component,unity_prefab:创建、搜索(返回instanceId),以及删除游戏对象层次结构,包括添加/删除组件和实例化预制件。unity_component_property,unity_component_manage:通过深度C#反射和调用组件方法获取/设置组件属性的高级控制。unity_asset,unity_asset_meta,unity_importer:文件移动、查找和直接修改.meta属性(例如纹理压缩、图像过滤器)通过SerializedProperty路径,而无需解析YAML。unity_scene,unity_scene_manage:保存、打开、创建场景和返回构建设置场景。unity_editor,unity_editor_state,unity_editor_execute_menu:检查编辑器状态(播放、暂停、编译),执行编辑器菜单项,并通过以下方式处理历史记录unity_history.unity_build_manage,unity_test_run,unity_package:CI/CD工具,用于获取/设置脚本定义、触发构建、检查包和运行EditMode/PlayMode测试。unity_console,unity_debug,unity_profiler:高效读取控制台日志、调试诊断和捕获性能统计数据。unity_ui,unity_camera,unity_cinemachine:统一UI创建(uGUI)、SceneView相机控件和Cinemachine编排。unity_physics,unity_navmesh,unity_terrain:用于对撞机、烘焙导航网格路径和地形雕刻的高级场景工具。unity_material,unity_shader,unity_light:控制渲染管道、材质上的颜色/纹理、着色器和全局照明调整。unity_animator,unity_timeline:Unity Animator的工作流和控制器操作,以及创作时间线序列。unity_script,unity_scriptableobject,unity_event:安全地管理C#脚本、编辑ScriptableObject资产和修改UnityEvents。unity_cleaner,unity_validation,unity_optimization:项目清理、运行项目验证、删除死代码和优化场景。unity_smart,unity_perception,unity_workflow:智能查询布局绑定、场景状态的深度内省/报告以及管理工作流历史。
______________________________________________________________________
🧠 核心开发人员技能
主要教学技能,教授Antigravity Unity和C#开发的最佳架构实践。
🏗️ 体系结构和C#标准
csharp-pro:教授现代C#(9.0+),包括记录、模式匹配、内存优化(跨度、值类型)和SOLID原理。csharp-async-patterns:严格的异步标准:通过CancellationToken,使用ConfigureAwait,避免async void.csharp-code-style:代码样式和命名约定(mPascalCase表示私有,bBoolean前缀)、项目代码组织和审查标准一致性。unity-csharp-fundamentals:Unity C#基本模式包括TryGetComponent,SerializeField,RequireComponent以及安全编码实践。unity-developer:开发负责人。基于组件的方法、缓存依赖关系、可寻址对象、脚本对象和状态机模式。unity-async:Unity中的线程细节。委派协程(遗留)和任务(现代),确保Unity API调用在主线程上严格执行。unity-collection-pool:通过使用训练AI来完全避免垃圾收集高峰ListPool和DictionaryPool从UnityEngine.Pool.
🚀 优化、测试和文档
unity-performance:通过分析、绘制调用减少、批处理、LOD和遮挡剔除进行优化。unity-mobile:使用IL2CPP、布局批处理和纹理压缩(ASTC/ETC2)对智能手机进行FPS优化。unity-testrunnerUnity测试框架CLI自动化、EditMode/PlayMode测试、NUnit断言和测试驱动开发(TDD)工作流。csharp-xml-docs:自动XML文档的严格标准:创建清晰 `,
, ` 用简明的英语。
______________________________________________________________________
🎨 UI和演示技巧
unity-ui:使用UI工具包和UGUI构建和优化Unity UI。响应式布局、事件系统和布局优化。unity-ui-creator:Unity中屏幕/HUD/菜单布局的绝对专家。教导如何使用锚点创建正确的画布层次结构,适应不同的屏幕,避免布局“闪烁”。unity-ui-layout-automation:根据已建立的项目模式自动化和验证Unity UI(uGUI)布局结构。unity-textmeshpro:对TMPro有深入了解:创建字体资源、富格文本、阴影/高光材质和动态性能。
______________________________________________________________________
⚙️ 元和系统技能
用于管理和开发人工智能系统和服务器基础设施的技能。
unified-unity-mcp:有关通过统一Unity MCP核心及其模块工具操作Unity编辑器的信息。skill-creator:创建有效技能的指南。教人工智能如何正确地制定、格式化和构建新的指令模块。
______________________________________________________________________
💡 有效提示示例
以下是完美查询(提示)的示例。他们指导Antigravity尽可能高效地使用嵌入式技能和统一MCP服务器。
🖥️ UI和布局技巧
Use the 'unity-ui-creator' skill. Build a highly responsive "Settings Menu" screen in the UI scene. It should have a background panel, vertical layout group in the center, 3 buttons (Audio, Graphics, Gameplay), and a close button anchored to the top right. Test it on 16:9 and notch displays.I need a ScrollView for an inventory system. Please structure the prefabs correctly, removing any unnecessary ContentSizeFitters to ensure 60fps scrolling.Use the 'unity-textmeshpro' skill to create a stylized "Game Over" title text. Apply a gold metallic material preset with a subtle drop shadow and ensure the font asset supports rich text formatting.Validate my HUD canvas hierarchy using the 'unity-ui-layout-automation' checks. Inject the missing UIAnimationBehaviour to the root if needed.
🧩 架构与C\#
Use the 'unity-developer' skill. I need to implement a state machine for my boss enemy. Use modern C# 9.0 features like pattern matching and switch expressions to handle phase transitions.Refactor my DataService layer using the 'csharp-async-patterns' skill. Remove all 'async void' methods except for UI click handlers, and ensure every web request properly accepts a CancellationToken.Use the 'unity-collection-pool' skill to rewrite my projectile spawner. Replace standard lists with ListPool from UnityEngine.Pool to eliminate GC spikes.Apply the 'csharp-code-style' skill to the entirety of the CombatManager.cs script. Fix all naming conventions so that private fields use the 'm' prefix and booleans use the 'b' prefix.Generate XML documentation for the IPlayerInventory interface using the 'csharp-xml-docs' skill. Keep it concise and use active voice.
🔋 优化和移动
Use the 'unity-performance' skill. Use the MCP to check the materials on all Environment meshes and turn on GPU Instancing for all of them using reflection.Review my project for mobile deployment using the 'unity-mobile' skill. Check the Texture Importer settings using 'unity_asset_meta' and ensure large UI sprites are using ASTC 6x6 compression.Use the MCP 'unity_console_read' tool to monitor my scene for 10 seconds. Identify if any scripts are wildly spamming Debug.Log and causing CPU bottlenecks.I have 30 identical trees in the scene. Use the MCP tools to find them all by their 'Tree' tag, and parent them under a single empty 'Environment' GameObject to clean up the hierarchy.
🛠️ 场景和对象操纵
Use the 'unity_gameobject_manage' tool to find the GameObject named 'PlayerSpotlight'. Then use 'unity_component_property' to dynamically change its Light intensity to 12.5 and its color to pure Red.I need to set up a Cinemachine Virtual Camera focusing on the Player. Instantiate the VCam prefab, then use reflection to set its Follow and LookAt targets to the Player's instanceId.Check the 'unity_editor_state'. If it is not compiling, trigger a full 'unity_test_run' on PlayMode. Output the results of any failed tests.Use the 'unity_asset_create' tool to scaffold 3 new empty folders in my project: Assets/Art/Characters, Assets/Audio/SFX, and Assets/Data/Configs.Find all GameObjects with the 'BoxCollider' component attached. For each one, use 'unity_component_property' to set their 'isTrigger' boolean to true.Use the 'unity_navmesh' MCP tool to bake a new navigation mesh for the current scene geometry.Save my current scene using 'unity_scene_manage', then open 'Assets/Scenes/Level_02.unity'. Once opened, find the 'SpawnPoint' object and move it to coordinates 10, 0, 50.
______________________________________________________________________
附言:顺便说一句,这是我在Antigravity中使用的扩展包,可以轻松地与Unity+C#配合使用:
C#(OmniSharp):智能感知、导航、重构、基本调试 https://open-vsx.org/extension/muhammad-sammy/csharp
.NET运行时工具:自动提取所需的。C#工具的NET运行时 https://open-vsx.org/extension/ms-dotnettools/vscode-dotnet-runtime
Unity附加调试器/集成:启动并附加到Unity编辑器/播放器 https://open-vsx.org/extension/Zlorn/vstuc
解决方案资源管理器:.sln/.csproj的便捷导航 https://open-vsx.org/extension/fernandoescolar/vscode-solution-explorer
Unity工具包:小巧但实用的Unity助手 https://open-vsx.org/extension/Tobiah/unity-tools
着色器支持:通过语言服务器使用HLSL/Unity着色器工具 https://open-vsx.org/extension/shader-ls/vscode-shader
Unity颜色预览:Color/Color32的内联预览 https://open-vsx.org/extension/clock-worked/vscode-unity-color-preview
Unity C#代码片段:常见Unity代码的快速模板 https://open-vsx.org/extension/kleber-swf/unity-code-snippets
