> 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/availability-reference.md).

# 对话可用性参考

用于控制 Convai Unity SDK 中玩家输入的对话可用状态、事件和方法的参考。

在生命周期和调用顺序中，参与检查角色是否能听到玩家的每个公共成员。

### `ConvaiConversationAvailability` 枚举

| 值             | 含义                                                     |
| ------------- | ------------------------------------------------------ |
| `NoCharacter` | 没有角色被提及，或者尚未设置。                                        |
| `Offline`     | 没有房间。没有任何东西在监听。                                        |
| `Connecting`  | 房间正在建立中。                                               |
| `Preparing`   | 房间已连接，但该角色尚未由服务确认。此时发送的消息会丢失。                          |
| `就绪`          | 该角色能听到玩家。                                              |
| `Answering`   | 该角色正在回答。仍然接受输入——这就是 barge-in。                          |
| `Unavailable` | 该角色启动失败，或已离开房间。不同于 `Connecting` 和 `Preparing`，这不会自行解决。 |

值按生命周期顺序列出。不要将它们与 `<` 或 `>` —— 接受输入的两个状态， `就绪` 和 `Answering`，并不相邻。

### `ConvaiConversationAvailabilityExtensions`

| 成员                       | 返回值   | 说明                                                 |
| ------------------------ | ----- | -------------------------------------------------- |
| `CanAcceptPlayerInput()` | `布尔值` | 当前发送的消息——无论是键入还是口述——是否会到达角色。对于 `就绪` 和 `Answering`. |
| `IsSettling()`           | `布尔值` | 给它一点时间后，该状态是否会自行解决。对于 `Connecting` 和 `Preparing`.  |

### `ConvaiManager` 成员

| 成员                                | 类型                                          | 说明                                                              |
| --------------------------------- | ------------------------------------------- | --------------------------------------------------------------- |
| `ConversationAvailability`        | `ConvaiConversationAvailability`            | 玩家是否可以与 `AddressedCharacter` 目前交谈，如果不可以，障碍是什么。                  |
| `ConversationAvailabilityChanged` | `事件 Action<ConvaiConversationAvailability>` | 在……时触发 `ConversationAvailability` 变化——包括当玩家开始与另一个可用性可能不同的角色交谈时。 |
| `AddressedCharacter`              | `ConvaiCharacter`                           | 玩家正在与之交谈的角色，无论房间以何种形式存在，也无论二者是否已存在。                             |

### `ConvaiCharacter` 成员

| 成员                         | 类型                               | 说明                                                                                                    |
| -------------------------- | -------------------------------- | ----------------------------------------------------------------------------------------------------- |
| `ConversationAvailability` | `ConvaiConversationAvailability` | 玩家当前是否可以与该角色交谈，如果不可以，障碍是什么。                                                                           |
| `CanAcceptPlayerInput`     | `布尔值`                            | 当前发送给该角色的消息——无论是键入还是口述——是否会到达它。等同于 `ConversationAvailability.CanAcceptPlayerInput()`.                 |
| `IsCharacterReady`         | `布尔值`                            | 角色是否已收到来自 Convai 的 bot-ready 信号。仅由该信号设置，而非由房间连接设置——这与 `ConversationAvailability`不同，后者还会考虑房间状态和名册成员资格。 |

### `ConversationAvailabilityChanged` 领域事件

发布到 SDK 的事件中心，并作为类型化属性公开在 `ConvaiEvents.OnConversationAvailabilityChanged`.

| 成员                     | 类型                               | 说明                                 |
| ---------------------- | -------------------------------- | ---------------------------------- |
| `可用性`                  | `ConvaiConversationAvailability` | 当前裁定。                              |
| `PreviousAvailability` | `ConvaiConversationAvailability` | 它所替代的裁定。                           |
| `角色 ID`                | `字符串`                            | 被提及角色的 Convai Character ID（如果有的话）。 |
| `CharacterName`        | `字符串`                            | 该角色的显示名称，用于日志和 UI。                 |
| `时间戳`                  | `DateTime`                       | 裁定变更时的 UTC 时间。                     |
| `CanAcceptPlayerInput` | `布尔值`                            | 玩家当前是否可以发送语音或文本。                   |

### `LocalPlayerActivityChanged` 领域事件

发布到 SDK 的事件中心，但没有类型化属性，位于 `ConvaiEvents` —— 通过 `ConvaiEvents.Raw`.

| 成员         | 类型                          | 说明                                                      |
| ---------- | --------------------------- | ------------------------------------------------------- |
| `IsActive` | `布尔值`                       | 是否 `来源` 当前能看到玩家。                                        |
| `来源`       | `LocalPlayerActivitySource` | 此事件报告的是哪种本地证据。                                          |
| `级别`       | `float`                     | 当电平门限触发此事件时，麦克风相对于其已稳定的噪声水平有多响。对于 `PushToTalk` 和下降沿时为零。 |
| `时间戳`      | `DateTime`                  | 本地证据变化时的 UTC 时间。                                        |

#### `LocalPlayerActivitySource` 枚举

| 值            | 含义                      |
| ------------ | ----------------------- |
| `Microphone` | 打开的麦克风听到的声音足够大，像是有人在说话。 |
| `PushToTalk` | 玩家正在按住按键通话控制。           |

同一个事件中心还会发布 `RoomRosterChanged` —— 在已连接房间中，角色加入、离开或被拒绝——并以 `ConvaiEvents.OnRoomRosterChanged`的形式公开。这不是可用性信号；参见 [处理房间事件](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/multi-character-sessions/handle-roster-events.md) 了解其字段和订阅模式。

### `ConvaiPlayer` 成员

| 成员                   | 签名                                                           | 说明                                  |
| -------------------- | ------------------------------------------------------------ | ----------------------------------- |
| `SendTextMessage`    | `void SendTextMessage(string message)`                       | 向被提及的角色发送文本消息。若被拒绝，则记录警告并不执行任何操作。   |
| `TrySendTextMessage` | `bool TrySendTextMessage(string message, out string reason)` | 发送文本消息，并报告其被拒绝的原因。返回 `是` 当消息已交给房间时。 |

### 相关

{% content-ref url="/pages/416bc976c2de7ded4dd1e60ced7894e179974b5b" %}
[对话可用性如何运作](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/conversation-availability/how-availability-works.md)
{% endcontent-ref %}

{% 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 %}


---

# 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/availability-reference.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.
