> 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/ui-and-presentation/notification-system/notification-system-reference.md).

# 通知系统参考

SONotification、SONotificationGroup、UINotificationController 和 SONotificationErrorMap 的参考文档——字段、方法和配置选项。

通知系统由 ScriptableObject 资源和控制器组件构成。有关设置说明以及如何通过代码触发通知，请参阅 [通知系统](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/ui-and-presentation/notification-system.md).

### `SONotification`

每条通知都是一个 `ScriptableObject` 资源，其中包含要显示的内容。

**创建方式：** 在 Project 窗口中右键单击 → **Create → Convai → Notification System → Notification**

**字段：**

| 字段                    | 类型       | 说明                                |
| --------------------- | -------- | --------------------------------- |
| `icon`                | `Sprite` | 显示在通知图标槽中的 Sprite。可选；留空则不显示图标     |
| `notificationTitle`   | `string` | 以粗体显示的标题文本                        |
| `notificationMessage` | `string` | 正文文本。支持多行内容                       |
| `Id`                  | `string` | 用于错误映射和去重冷却的稳定字符串标识符。若留空，则默认为资源名称 |

**用于在运行时创建通知的流式 setter：**

| 方法                           | 返回类型             | 说明            |
| ---------------------------- | ---------------- | ------------- |
| `SetTitle(string title)`     | `SONotification` | 设置通知标题        |
| `SetMessage(string message)` | `SONotification` | 设置通知正文文本      |
| `SetIcon(Sprite newIcon)`    | `SONotification` | 设置通知图标 Sprite |

这些方法返回 `this`，因此可以链式调用：

```csharp
var notification = ScriptableObject.CreateInstance<SONotification>();
notification
    .SetTitle("Scenario Complete")
    .SetMessage("All required steps have been completed. Proceed to debrief.")
    .SetIcon(successIcon);
```

### `SONotificationGroup`

`SONotificationGroup` 注册场景可识别的所有 `SONotification` 资源。 `NotificationHandler` 在运行时根据此组解析通知 ID。

**创建方式：** 右键单击 → **Create → Convai → Notification System → Notification Group**

**字段：**

| 字段                | 类型                 | 说明                              |
| ----------------- | ------------------ | ------------------------------- |
| `soNotifications` | `SONotification[]` | 所有可供 `SONotification` 通知系统使用的资源 |

**静态查找方法：**

| 方法                                                                   | 返回类型   | 说明                                                            |
| -------------------------------------------------------------------- | ------ | ------------------------------------------------------------- |
| `GetGroup(out SONotificationGroup group)`                            | `bool` | 从以下位置加载组 `Resources/SONotificationGroup`。如果资源缺失，则返回 `false` 。 |
| `TryGetById(string notificationId, out SONotification notification)` | `bool` | 根据通知的 `Id` 字段查找通知。如果没有匹配项，则返回 `false` 。                       |

```csharp
if (SONotificationGroup.GetGroup(out SONotificationGroup group))
{
    if (group.TryGetById("scenario-complete", out SONotification notification))
    {
        // 使用通知
    }
}
```

{% hint style="danger" %}
组资源必须保存到 `Assets/Resources/SONotificationGroup.asset`。运行时使用的路径字符串为 `"SONotificationGroup"` ——不含文件扩展名，也不含子目录。如果资源缺失， `NotificationHandler` 会记录 `"[NotificationHandler] SONotificationGroup asset could not be resolved."` ，并且不会显示任何通知。
{% endhint %}

### `UINotificationController`

管理可重复使用的 `UINotification` 元素池，并控制每条通知的滑动动画。

**Inspector 字段：**

| 字段                           | 类型               | 默认值   | 说明                         |
| ---------------------------- | ---------------- | ----- | -------------------------- |
| `uiNotificationPrefab`       | `UINotification` | —     | `UINotification` 用于对象池的预制件 |
| `spacing`                    | `int`            | `100` | 堆叠通知之间的垂直像素间距              |
| `activeNotificationPos`      | `Vector2`        | —     | 可见通知显示的锚定位置                |
| `deactivatedNotificationPos` | `Vector2`        | —     | 隐藏通知在屏幕外等待时的锚定位置           |
| `activeDuration`             | `float`          | `4.0` | 通知滑出前保持可见的秒数               |
| `slipDuration`               | `float`          | `0.3` | 滑入和滑出动画的持续秒数               |
| `delay`                      | `float`          | `0.3` | 滑动动画开始前的延迟秒数               |
| `slipAnimationCurve`         | `AnimationCurve` | —     | 滑动动画的缓动曲线                  |

**并发与排队：** 最多可同时显示 3 条通知。当 3 条通知处于活动状态时收到第 4 条通知请求，它会进入队列，并在其中一条活动通知关闭后立即显示。

**每条通知的动画顺序：** 滑入（`slipDuration`）→ 显示 `activeDuration` → 延迟（`delay`）→ 滑出（`slipDuration`）→ 开始显示下一个排队的通知。

### `SONotificationErrorMap`

使用有序规则列表，将会话错误代码字符串映射到 `SONotification` 资源。自动从 `Resources/SONotificationErrorMap` 加载，也可以手动指定。

**创建：** 右键单击 → **创建 → Convai → 通知系统 → 会话错误映射**

保存到 `Assets/Resources/SONotificationErrorMap.asset` 以便自动加载。

**字段：**

| 字段      | 类型                                   | 说明                        |
| ------- | ------------------------------------ | ------------------------- |
| `Rules` | `List<SessionErrorNotificationRule>` | 错误到通知的有序规则列表。优先使用第一个匹配的规则 |

#### `SessionErrorNotificationRule`

| 字段             | 类型                      | 说明                                       |
| -------------- | ----------------------- | ---------------------------------------- |
| `ErrorPattern` | `string`                | 用于匹配会话错误的错误代码字符串                         |
| `MatchType`    | `SessionErrorMatchType` | `Exact` — 完全匹配字符串。 `Prefix` — 错误代码以此模式开头 |
| `Notification` | `SONotification`        | `SONotification` 此规则匹配时要显示的资源            |

规则按从上到下的顺序进行评估。将更具体的规则放在范围更广的前缀匹配规则上方。

**规则配置示例：**

| 错误模式          | 匹配类型     | 通知                             |
| ------------- | -------- | ------------------------------ |
| `AUTH_FAILED` | `Exact`  | `Notification_AuthError`       |
| `CONNECTION_` | `Prefix` | `Notification_ConnectionError` |
| `RATE_LIMIT`  | `Exact`  | `Notification_RateLimit`       |

### 后续步骤

{% content-ref url="/pages/1e289d6d26e0f600f68032dc64a489bc29fe1a00" %}
[通知系统](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/ui-and-presentation/notification-system.md)
{% endcontent-ref %}

{% content-ref url="/pages/5f60eaa8d444f5ee8a995392852da827736d3b54" %}
[自定义 UI 组件](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/ui-and-presentation/customizing-ui-components.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/ui-and-presentation/notification-system/notification-system-reference.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.
