> 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` 值：

| 状态            | 含义                                                     |
| ------------- | ------------------------------------------------------ |
| `NoCharacter` | 当前没有正在被对话的角色，或者场景尚未设置。                                 |
| `Offline`     | 没有房间。没有任何东西在监听。                                        |
| `Connecting`  | 房间正在建立中。                                               |
| `Preparing`   | 房间已连接，但服务还没有确认这个角色。此时发送的消息会丢失。                         |
| `就绪`          | 该角色能听到玩家。                                              |
| `Answering`   | 该角色正在回答。输入仍然会被接受——在角色回答到一半时打断它属于正常对话，而不是被拒收的消息。        |
| `Unavailable` | 该角色启动失败，或已离开房间。不同于 `Connecting` 和 `Preparing`，这不会自行解决。 |

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

### 要问哪个问题

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

* `CanAcceptPlayerInput()` — 现在发送的消息，无论是键入的还是说出的，是否会到达角色。仅当 `就绪` 和 `Answering`.
* `IsSettling()` — 该状态是否会自行结束，而不需要告诉玩家做任何事。仅当 `Connecting` 和 `Preparing`.

### 正在向谁提问

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

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

### 在目标切换过程中

`ConvaiManager.ConversationAvailabilityChanged` 会在判断结果发生变化时触发——包括玩家开始转而对另一个角色说话，而该角色的可用性与他刚离开的那个不同的时候。当目标切换正在进行时，可用性会报告 `Preparing` 即使对于一个在 `就绪` 前一刻还是如此的角色也是这样，因此当对话实际上正在角色之间切换，而不是接受一条最终落不到任何一方的消息时，输入会在那一刻关闭。

### 相关概念

{% 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 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/conversation-availability/how-availability-works.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.
