关于 unity-profiler
unity-profiler 是一组用于读取 Unity 运行时性能数据的技能,适合需要检查帧率、内存和渲染指标的开发者。它提供瞬时只读快照,不控制 Profiler 录制。
主要功能
- 01读取 FPS、内存和批次数
- 02查看运行时内存占用对象
- 03统计纹理、网格、材质和音频内存
- 04获取渲染统计数据
- 05统计已加载对象与 AssetBundle
适用场景
- 01检查运行时帧率和批次数
- 02定位内存占用较高的运行时对象
- 03查看纹理或网格的内存用量
- 04检查渲染指标及已加载 AssetBundle
MCP 相关
这些只读技能可由 MCP 客户端调用,以获取 Unity 的性能与内存快照数据。
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ besty0728/ unity-skills --skill unity-profiler安装后在 Claude Code 中输入/unity-profiler确认已加载。
详细介绍
**调用本模块中的任何技能前:**如果你准备根据技能名称或描述猜测参数后调用技能,请先停下——先阅读此文件(或通过
GET /skills/recommend?includeSchema=true获取其架构)。如果你已从 recommend/schema 获取参数定义,则可直接进行 dryRun。
触发条件
- 检查运行时性能
- 获取 profiler 快照
- 检查内存/帧统计
- 查看运行时性能、抓取 profiler 快照、检查内存/帧率统计
Profiler 技能
获取性能统计信息。
操作模式
- Approval / Auto / Bypass:所有技能均直接执行。本模块中的全部技能都标记为
ReadOnly = true, Mode = SkillMode.SemiAuto,三种模式下都不需要 grant。 - 本模块不包含 Delete / PlayMode / Reload / RiskLevel=high 类技能 —— 无需经过
IsForbiddenInSemi拦截。 - 注:本组技能仅用于读取“瞬时快照”,并非 Profiler 录制控制;如需持续采样,请使用 Unity Profiler 窗口。
切勿(常见幻觉):
profiler_start/profiler_stop不存在 → profiler 技能是只读快照,不是录制控制profiler_record不存在 → 请使用 Unity Profiler 窗口进行录制profiler_analyze/profiler_get_fps不存在 → 使用profiler_get_stats(FPS、批次、绘制调用)或profiler_get_memory(堆大小)
路由:
- 获取场景性能提示 → 使用
perception模块的scene_performance_hints - 获取内存信息 → 使用
debug_get_memory_info(debug 模块)或profiler_get_memory(本模块) - 获取优化建议 → 使用
optimization模块
技能
profiler_get_stats
获取性能统计信息(FPS、内存、批次)。 参数: 无。
返回:
{
"fps": 60.0,
"triangles": 1500,
"batches": 12,
"memory": { "totalAllocatedMB": 256.5, ... }
}
profiler_get_memory
获取内存使用概览(总分配量、预留量、mono 堆)。 参数: 无。
返回: { success, totalAllocatedMB, totalReservedMB, unusedReservedMB, monoHeapMB, monoUsedMB }
profiler_get_runtime_memory
获取场景中运行时内存占用最高的前 N 个对象。
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| limit | int | 否 | 20 | 返回的对象数量上限 |
返回: { success, totalTrackedMB, showing, objects: [{ name, type, sizeKB }] }
profiler_get_texture_memory
获取所有已加载纹理的内存使用情况。
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| limit | int | 否 | 50 | 返回的纹理数量上限 |
返回: { success, totalCount, totalMB, topTextures: [{ name, type, sizeKB, width, height }] }
profiler_get_mesh_memory
获取所有已加载网格的内存使用情况。
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| limit | int | 否 | 50 | 返回的网格数量上限 |
返回: { success, totalCount, totalMB, topMeshes: [{ name, sizeKB, vertices, triangles }] }
profiler_get_material_memory
获取所有已加载材质的内存使用情况。
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| limit | int | 否 | 50 | 返回的材质数量上限 |
返回: { success, totalCount, totalMB, topMaterials: [{ name, shader, sizeKB }] }
profiler_get_audio_memory
获取所有已加载 AudioClip 的内存使用情况。
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| limit | int | 否 | 50 | 返回的片段数量上限 |
返回: { success, totalCount, totalMB, topClips: [{ name, sizeKB, length, channels, frequency }] }
profiler_get_object_count
按类型统计所有已加载对象的数量。
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| topN | int | 否 | 20 | 返回的数量最多的类型数 |
返回: { success, totalObjects, topTypes: [{ type, count }] }
profiler_get_rendering_stats
获取渲染统计信息(批次、三角形、顶点等)。 参数: 无。
返回: { success, frameTime, renderTime, triangles, vertices, batches, setPassCalls, drawCalls, dynamicBatchedDrawCalls, staticBatchedDrawCalls, instancedBatchedDrawCalls, shadowCasters }
profiler_get_asset_bundle_stats
获取所有已加载 AssetBundle 的信息。 参数: 无。
返回: { success, count, bundles: [{ name, isStreamedSceneAssetBundle }] }
精确签名
精确名称、参数、默认值和返回值由 GET /skills/schema 或 unity_skills.get_skill_schema() 定义,不由本文档定义。