> 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/conversation-availability/how-availability-works.md).

# 对话可用性如何运作

了解 Convai Unity SDK 如何判断某个角色是否能听到玩家，以及为什么仅仅连接到房间还不够。

房间可能会在 Convai 还未宣布玩家正在对话的角色之前，就报告自己已连接。会话可用性回答的是比「房间是否已连接」更窄的问题——它问的是「这个特定角色现在能听到玩家吗」——而且它是 SDK 中每个输入入口在允许玩家说话或输入之前都会检查的内容。

### 为什么已连接不等于可用

房间报告已连接并不意味着被指向的角色已经被服务确认。此间输入的一句问候会被接受、发送并丢失——没有任何日志记录它，也没有任何东西告诉玩家为什么没人回应。 `ConvaiManager.ConversationAvailability` 弥补了这一空白。请将输入绑定到它，而不是绑定到房间是否已连接。

### 按生命周期顺序排列的状态

`ConvaiManager.ConversationAvailability` 返回一个 `ConvaiConversationAvailability` 值：

| 状态    | 含义                                            |
| ----- | --------------------------------------------- |
| `无角色` | 没有任何角色被指向，或者场景还没有设置好。                         |
| `离线`  | 没有房间。没有任何东西在监听。                               |
| `连接中` | 房间正在建立。                                       |
| `准备中` | 房间已连接，但服务还没有确认这个角色。现在发送的消息会丢失。                |
| `就绪`  | 角色可以听到玩家。                                     |
| `回答中` | 角色正在回答。输入仍然会被接受——在角色回答过程中打断它属于正常对话，而不是被拒绝的消息。 |
| `不可用` | 角色启动失败，或者离开了房间。不同于 `连接中` 和 `准备中`，它不会自行恢复。     |

不要将这些值与 `<` 或 `>`. `就绪` 和 `回答中` 是接受玩家输入的两个状态，而且它们在列表中并不相邻。

### 该问哪个问题

两个扩展方法回答了 UI 实际上关心的问题：

* `CanAcceptPlayerInput()` ——现在发送的消息，无论是打字还是口述，是否能到达角色。仅在 `就绪` 和 `回答中`.
* `IsSettling()` ——该状态是否会自行结束，而无需提示玩家做任何事。仅在 `连接中` 和 `准备中`.

### 正在询问的是谁

`ConvaiManager.ConversationAvailability` 对……作出回答 `ConvaiManager.AddressedCharacter` ——玩家当前正在与之交谈的任意角色，无论房间是否保留多个角色的名册。相同的答案也可在每个角色的 `ConvaiCharacter.ConversationAvailability`.

`ConvaiCharacter.ConversationAvailability` 位于 `ConvaiCharacter.IsCharacterReady`旁边，这两者很容易混淆。 `IsCharacterReady` 由 Convai 的角色就绪信号设置一次，不会自行清除。 `ConversationAvailability` 还会考虑房间是否已连接、该角色是否仍在共享房间的名册中占有一个席位，以及该角色当前是否正在说话——因此一个角色可能会报告 `IsCharacterReady == true` 在先前连接中为 true，而 `ConversationAvailability` 报告 `不可用`，因为它在当前房间里已经不再占有席位。

### 切换目标期间

`ConvaiManager.ConversationAvailabilityChanged` 只要判定发生变化就会触发——包括玩家开始指向另一个角色，而该角色的可用性与刚离开的角色不同的时候。在目标切换进行中时，可用性会报告 `准备中` 即使对于一个曾在刚才 `就绪` 之前的某一刻还是可用的角色，因此输入会在对话真正于角色之间切换的那一刻关闭，而不是接受一条落不到任何一方的消息。

### 相关概念

{% content-ref url="/pages/66ee7fe1bbd8fe5aba610cee8f0dfd2573443acf" %}
[根据可用性控制 UI](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/conversation-availability/gate-your-ui.md)
{% endcontent-ref %}

{% content-ref url="/pages/1de47e20d64086de6ea2148c4871a665eec92182" %}
[多角色会话工作原理](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/multi-character-sessions/how-multi-character-sessions-work.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/conversation-availability/how-availability-works.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.
