> For the complete documentation index, see [llms.txt](https://docs.convai.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/vision/debug-preview.md).

# Vision 调试预览

`VisionDebugPreview` 是一个仅编辑器组件，会将实时摄像头画面渲染为屏幕覆盖层，并显示捕获统计面板。可在发布前的开发阶段用它来回答“AI 实际看到了什么？”。示例调试中心的 **Vision** 面板通过确认视觉状态请求和触发实际上是否到达 Convai 来补充这一点。

### 将组件添加到

在任意场景 GameObject 上，点击 **Add Component** → **Convai/Vision/视觉调试预览（仅编辑器）**.

该组件会自动发现场景中的活动帧源。除非存在多个帧源，否则无需显式分配。

{% hint style="info" %}
`VisionDebugPreview` 按优先级顺序发现帧源：同一 GameObject、子对象、父对象，然后是全场景搜索。当存在多个帧源时，请显式分配 **Frame Source Component** 字段，以避免歧义。
{% endhint %}

### 检查器引用

**预览设置**

| 字段       | 类型     | 默认值    | 描述          |
| -------- | ------ | ------ | ----------- |
| **显示预览** | `bool` | `true` | 启用摄像头画面覆盖层。 |
| **显示统计** | `bool` | `true` | 启用捕获统计面板。   |

**来源**

| 字段                         | 类型              | 默认值      | 描述                                          |
| -------------------------- | --------------- | -------- | ------------------------------------------- |
| **Frame Source Component** | `MonoBehaviour` | *（自动发现）* | 要预览的帧源。留空以自动发现。                             |
| **回退到活动帧源**                | `bool`          | `true`   | 当分配的源没有纹理时，会在场景中搜索另一个活动帧源。当源在预览之后才启动时，这很有用。 |

**覆盖层布局**

| 字段        | 类型              | 默认值   | 描述                                                 |
| --------- | --------------- | ----- | -------------------------------------------------- |
| **覆盖层位置** | `预览位置`          | `右下角` | 预览锚定到 Game 视图哪个角落。可选项： `左上角`, `右上角`, `左下角`, `右下角`. |
| **覆盖层宽度** | `int` （160–640） | `320` | 预览宽度（像素）。高度会根据宽高比自动计算。                             |
| **X 偏移**  | `int` （0–200）   | `10`  | 相对于所选角落的水平内边距（像素）。                                 |
| **Y 偏移**  | `int` （0–200）   | `10`  | 相对于所选角落的垂直内边距（像素）。                                 |

<figure><img src="/files/909efd2cfbd8e5bd85928e048668544d665e6c2b" alt="Debug preview overlay positioning controls in the Inspector"><figcaption><p>调试预览覆盖层定位控件。</p></figcaption></figure>

**宽高比**

| 字段         | 类型            | 默认值            | 描述                                                   |
| ---------- | ------------- | -------------- | ---------------------------------------------------- |
| **使用源宽高比** | `bool`        | `true`         | 启用后，会从帧源的 `FrameDimensions`中导出宽高比。禁用时，使用 **自定义宽高比**. |
| **自定义宽高比** | `float` （1–3） | `1.778` (16:9) | 当 **使用源宽高比** 未启用时使用的宽高比。                             |

### 统计覆盖层

当 **显示统计** 启用后，会在预览旁边绘制一个文本框。具体输出如下：

```
视觉捕获调试
状态：捕获中
来源：ConvaiVisionRoot/ConvaiVisionRoot [camera] (CameraVisionFrameSource)
分辨率：1280x720
FPS：14.9（目标：15）
帧数：447
```

| 行               | 来源                              | 说明                                 |
| --------------- | ------------------------------- | ---------------------------------- |
| `状态：捕获中 / 已停止`  | `IsCapturing` 在帧源上              | 布尔字符串 — 不是 `VisionSourceState` 枚举。 |
| `来源：...`        | 层级路径 + SourceId + 类型名称          | 用于消歧的场景根节点完整路径。                    |
| `分辨率：WxH`       | `FrameDimensions`               | `(0, 0)` 在捕获开始之前。                  |
| `FPS：X.X（目标：Y）` | 按 0.5 秒间隔测量 + `TargetFrameRate` | 测得的 FPS 每 0.5 秒更新一次。               |
| `帧数：N`          | `FrameCount`                    | 自捕获开始以来的累计总帧数。                     |

<figure><img src="/files/efb0ea40846e0570464bc740db8e18dcac0fc59e" alt="Statistics panel showing FPS and frame metrics in the Vision Debug Preview overlay"><figcaption><p>显示 FPS 和帧指标的统计面板。</p></figcaption></figure>

{% hint style="warning" %}
**`IsCapturing` 与 `IsPublishing`:** 统计面板显示 `IsCapturing` ——帧源是否正在生成帧。这与 `ConvaiVisionPublisher.IsPublishing`不同，后者表示 WebRTC 视频轨道是否正在主动发送到 Convai。两者可以独立检查；帧源可能正在捕获，而发布可能已暂停或尚未开始。
{% endhint %}

### 脚本访问

这些属性可从其他脚本中读取：

| 属性            | 类型      | 描述                     |
| ------------- | ------- | ---------------------- |
| `ShowPreview` | `bool`  | 获取或设置预览覆盖层是否可见。        |
| `ShowStats`   | `bool`  | 获取或设置统计面板是否可见。         |
| `CurrentFps`  | `float` | 测得的捕获 FPS，每 0.5 秒更新一次。 |
| `FrameCount`  | `long`  | 当前帧源的累计帧数。             |
| `IsCapturing` | `bool`  | 当前帧源是否正在捕获。            |

### 使用示例调试中心验证视觉请求

`VisionDebugPreview` 确认帧源正在本地生成帧。它不能确认 Convai 是否接收到了这些帧，也不能确认视觉相关请求是否得到了回复。请从 Package Manager 导入 **LipSync 示例** 并打开其场景来测试这个往返流程。该示例会放置一个 **示例调试中心** ，其中包含一个 **Vision** 面板以及其 **Context** 和 **Emotion** 面板。

打开 **Vision** 面板以访问这些控件：

| 控件                                 | 操作                                                                                |
| ---------------------------------- | --------------------------------------------------------------------------------- |
| **文本消息** 输入 + **发送文本**             | 通过 `ConvaiPlayer.SendTextMessage`发送一条纯文本消息。请先用它来确认角色是否有任何回应。                      |
| **视觉提示词** 和 **响应模式** 输入 + **视觉状态** | 调用 `ConvaiRoomManager.RequestVisionStatus()`。当 Convai 响应后，结果文本会报告后端的缓冲结果、活动源以及帧龄。 |
| **视觉提示词** 和 **响应模式** 输入 + **视觉触发** | 调用 `ConvaiRoomManager.TriggerVision()` 以及提示文本和解析后的响应模式。结果文本会报告是否附加了帧，以及请求是否被降级。   |

该 **响应模式** 输入接受 `silent`, `auto`，或 `must_respond`。在请求发送之前，无法识别的值会被拒绝。随后结果文本会显示 `无效的响应模式“<value>” — 请使用 silent、auto 或 must_respond`.

例如，在一次成功触发后，结果文本会显示：

```
视觉触发：status=success, outcome=frames_available, attach=attached, frames=5, downgraded=False
```

如果只想在不使用中心面板的情况下进行场景检查，请添加 `DynamicVisionContextSceneTool` 到任意 GameObject。它通过 IMGUI 覆盖层和等效的上下文菜单命令（**发送文本消息**, **请求视觉状态**, **触发视觉**）提供相同的三个操作。LipSync 示例场景还放置了一个视觉目标装置——角色前方的彩色道具——供 **视觉触发** 请求描述。

### 已知限制

* 仅编辑器。 `VisionDebugPreview` 调用 `enabled = false` 在 `Awake()` 非编辑器构建中关闭。发布构建中没有运行时开销。
* 在 WebGL 上，覆盖层是空白的，因为 `ConvaiVisionPublisher` 会绕过帧源并直接使用 `canvas.captureStream()` 直接。没有 `RenderTexture` 可显示的内容。请通过 `IsPublishing` 来代替。
* 覆盖层通过 `OnGUI` （IMGUI）渲染。它不能通过 UGUI 定位，也不能在世界空间中渲染。
* 每个 `VisionDebugPreview` 组件只会绘制一个统计面板。如果你需要并排比较两个帧源，请添加多个组件。
* `VisionContextDebugPanel` 和 `DynamicVisionContextSceneTool` 是位于 `SamplesShared/`下的仅示例组件。它们不是运行时 SDK 的一部分，除非你导入并保留该示例，否则不会包含在发布构建中。

### 下一步

{% content-ref url="/pages/b15c237537e3521d8e360ca90de5e9b15be340ec" %}
[发布策略](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/vision/publishing-and-policies.md)
{% endcontent-ref %}

{% content-ref url="/pages/86612bc613c5a299a468b71b3fb8a40e625ee1fe" %}
[排查视觉问题](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/vision/troubleshooting-and-diagnostics.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/vision/debug-preview.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
