> 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).

# 视觉调试预览

使用 Unity Editor 调试工具验证视觉摄像机画面，并确认视觉状态请求和触发器已到达 Convai。

`VisionDebugPreview` 这是一个仅编辑器组件，会将实时摄像头画面渲染为屏幕叠加层，并显示捕获统计面板。可在发布前的开发阶段用它来回答“AI 实际看到了什么？”。Sample Debug Hub 的 **视觉** 面板通过确认视觉状态请求和触发是否真正到达 Convai 来与之互补。

### 添加该组件

在任意场景 GameObject 上，点击 **添加组件** → **Convai/Vision/Vision Debug Preview（仅限编辑器）**.

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

{% hint style="info" %}
`VisionDebugPreview` 会按优先级顺序发现帧源：同一 GameObject、子对象、父对象，然后是全场景搜索。 **帧源组件** 当存在多个帧源时，请显式指定
{% endhint %}

### 字段以避免歧义。

**检查器参考**

| 字段       | 类型     | 默认     | 说明        |
| -------- | ------ | ------ | --------- |
| **预览设置** | `bool` | `true` | 显示预览      |
| **显示统计** | `bool` | `true` | 启用捕获统计面板。 |

**来源**

| 字段          | 类型              | 默认       | 说明                                          |
| ----------- | --------------- | -------- | ------------------------------------------- |
| **帧源组件**    | `MonoBehaviour` | *（自动发现）* | 要预览的帧源。留空即可自动发现。                            |
| **回退到活动帧源** | `bool`          | `true`   | 当已分配的源没有纹理时，会在场景中搜索另一个活动帧源。适用于源在预览之后才启动的情况。 |

**叠加层布局**

| 字段        | 类型                | 默认    | 说明                                                |
| --------- | ----------------- | ----- | ------------------------------------------------- |
| **叠加层位置** | `PreviewPosition` | `右下角` | 预览锚定到 Game 视图哪个角落。选项： `左上角`, `右上角`, `左下角`, `右下角`. |
| **叠加层宽度** | `int` （160–640）   | `320` | 预览宽度（像素）。高度会根据宽高比自动计算。                            |
| **X 偏移**  | `int` （0–200）     | `10`  | 从所选角落向内的水平缩进（像素）。                                 |
| **Y 偏移**  | `int` （0–200）     | `10`  | 从所选角落向内的垂直缩进（像素）。                                 |

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2Ft5AyxDxkoyD5skspgECG%2Fimage.png?alt=media&amp;token=4707ffc6-1b10-4354-9ac6-354a1e6ac32e" 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="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FIGx16w1tGysCNKWIiSVJ%2Fimage.png?alt=media&amp;token=786e43d4-ceaf-49ec-825c-a9a13f6df15f" 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`  | 当前帧源是否正在捕获。            |

### 使用 Sample Debug Hub 验证视觉请求

`VisionDebugPreview` 可确认帧源是否在本地产生帧。它不能确认 Convai 是否收到了这些帧，也不能确认特定于视觉的请求是否得到了响应。请从 Package Manager 导入 **LipSync 示例** 并打开其场景，以测试这一来回流程。该示例会实例化一个 **示例调试中心** 并传入一个 **视觉** 面板以及其 **上下文** 和 **情绪** 面板。

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

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

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

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

```
视觉触发：状态=success，结果=frames_available，附加=attached，帧数=5，降级=False
```

若只进行场景内检查而不使用 hub，请添加 `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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
