> 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/unity-plugin-beta-overview/features/emotion.md). Agents can also search and read this documentation through its [MCP server](https://docs.convai.com/api-docs/~gitbook/mcp).

# 情绪

情绪系统如何工作、每个组件的作用以及下一步该做什么——为任何 Convai 角色添加面部情绪的起点。

## 赋予 Convai 角色能够响应情绪的面部表情

Emotion 系统会将 Convai AI 的内部情绪状态转换为实时面部动画，驱动混合形状、Animator 参数，或同时驱动两者。每当后端判定角色感到喜悦、愤怒、惊讶或处于其他情绪状态时，Emotion 系统都会接收相应信号，将其平滑处理为自然的变化曲线，并实时将结果应用到角色面部。最终，角色会呈现出真实的情绪，而不是面无表情。

## 工作原理

```mermaid
flowchart TD
    A([Convai Backend]) -->|RTVI bot-emotion message\nemotion label + scale 1–3| B[RTVIBotEmotionMessage]
    B --> C[CharacterEmotionChanged\ndomain event]
    C --> D[ConvaiEmotionController]
    D --> E{Taxonomy\nresolution}
    E -->|alias → canonical label| F[EmotionScoreAccumulator\nsmoothing · micro-burst]
    F --> G[NeutralAlternator\nperiodic fade-to-neutral]
    G --> H{Output bindings}
    H --> I[BlendshapeEmotionBinding\nfacial blendshapes]
    H --> J[AnimatorParameterEmotionBinding\nAnimator float params]
    I & J --> K([EmotionReading\nread by your scripts])
```

后端会发送一个简短的情绪标签（例如 `"happy"`）以及一个取值范围为 1–3 的强度值。 **情绪分类体系** 会将该标签解析为其规范形式（`"joy"`），将强度归一化为 0–1 的分数，然后传递给 **分数累加器**；累加器会进行指数平滑，并可选择加入微表情爆发效果。 **中性表情交替器** 随后会定期将表情渐变回中性，以防面部表情僵住。最后，平滑后的分数会通过可配置的 **输出绑定**.

## 前提条件

{% hint style="info" %}
将 Emotion 系统添加到角色之前，请确保：

* 角色网格具有面部混合形状，或者 Animator Controller 中有要由情绪驱动的浮点参数。即使没有这些配置，管线也能运行，但至少配置一个输出绑定后才会产生视觉效果。
  {% endhint %}

## 组件的放置位置

| 组件                          | 放置位置                                          | 备注                                                   |
| --------------------------- | --------------------------------------------- | ---------------------------------------------------- |
| `ConvaiEmotionController`   | 在 **NPC 的根 GameObject**上，与 Embodiment 组件并列    | 每个角色一个                                               |
| `ConvaiEmotionProfile`      | 放在 `Assets/` 文件夹中的任意位置，作为 ScriptableObject 资源 | 如有需要，可供多个 NPC 预制件共享                                  |
| `EmotionTaxonomyAsset`      | 放在 `Assets/` 文件夹中的任意位置                        | 可选 — 不添加时使用内置的 Plutchik 集合                           |
| `ConvaiCharacterEventRelay` | 场景中的任意 GameObject 上                           | 自动解析同一 GameObject 上的 `ConvaiCharacter` ；如有需要，可拖入其他角色 |

## 关键概念

<table><thead><tr><th width="267.5">概念</th><th>说明</th></tr></thead><tbody><tr><td><code>ConvaiEmotionController</code></td><td>负责管理单个 NPC 整个管线的 MonoBehaviour。每个角色添加一个。</td></tr><tr><td><code>ConvaiEmotionProfile</code></td><td>一个 ScriptableObject 资源，包含所有可调参数：平滑、微爆发、中性表情交替以及输出槽位定义。</td></tr><tr><td><code>EmotionTaxonomyAsset</code></td><td>一个定义情绪词汇的 ScriptableObject，包括规范标签、服务器别名和嘴部影响提示。内置默认词汇包含 Plutchik 的八种基本情绪和中性情绪。</td></tr><tr><td><code>输出绑定</code></td><td><code>BlendshapeEmotionBinding</code> 和 <code>AnimatorParameterEmotionBinding</code> 会将每个规范情绪标签映射到网格 BlendShape 名称或 Animator 浮点参数。</td></tr><tr><td><code>EmotionReading</code></td><td>当前情绪状态的不可变快照：主导情绪标签、主导分数、所有分数，以及供 LipSync 使用的嘴部影响提示。每帧都可通过 <code>ConvaiEmotionController.Current</code>.</td></tr><tr><td><code>微爆发</code></td><td>新情绪到来时应用的短暂过冲，使表情在稳定到持续状态之前更有冲击力。</td></tr><tr><td><code>中性表情交替</code></td><td>一个定时器，会定期使当前表情淡化至中性再恢复，避免角色在长时间对话轮次中一直维持同一个表情。</td></tr><tr><td><code>ConvaiCharacterEventRelay</code></td><td>一个便于在 Inspector 中使用的组件，可将情绪变化回调公开为 Unity Events——无需编写代码。</td></tr></tbody></table>

## 本节内容

<table data-view="cards"><thead><tr><th></th><th></th></tr></thead><tbody><tr><td><strong>快速入门</strong></td><td>添加 Emotion Controller，指定随附配置文件，即可让 NPC 在对话中表现出情绪反应——无需创建自定义资源。</td></tr><tr><td><strong>情绪配置文件</strong></td><td>在一个可移植资源中配置平滑速度、微表情爆发、中性表情交替和输出绑定。</td></tr><tr><td><strong>输出绑定</strong></td><td>将平滑后的情绪分数映射到面部 BlendShape 和 Animator 浮点参数，并可按槽位控制权重和 LipSync。</td></tr><tr><td><strong>情绪分类体系</strong></td><td>了解内置的 Plutchik 情绪词汇、服务器别名的解析方式，以及如何创建自定义分类体系。</td></tr><tr><td><strong>脚本 API</strong></td><td>读取实时情绪状态、注入覆盖值、锁定表情并响应情绪事件——从 Inspector 中继到强类型 C# 订阅，应有尽有。</td></tr><tr><td><strong>用法示例</strong></td><td>完整示例涵盖危险触发器、锁定问候、困扰分支处理、分析日志记录和 Editor 调试。</td></tr><tr><td><strong>故障排除与诊断</strong></td><td>针对最常见问题提供分步解决方案——从表情无法变化到 LipSync 冲突和生产构建注意事项。</td></tr></tbody></table>

## 总结

Emotion 系统为 Convai 角色赋予可信的情感表现——由服务器驱动、经过平滑处理，并且在常见场景下无需编写代码即可全面配置。先从“快速入门”开始，让角色实时做出反应；然后参阅更深入的配置页面，根据具体的角色绑定和场景调整行为。


---

# 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/unity-plugin-beta-overview/features/emotion.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.
