> 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/utilities/dialogue-animation/usage-examples.md).

# 对话动画使用示例

这些示例从纯 Inspector 配置逐步过渡到用于运行时行为变化的 C# 脚本。请先查看示例 1，以理解基础配置模式，然后再阅读后续示例，以了解何时以及如何使用脚本。

***

### 示例 1 — 工业安全讲师

**场景：** 工厂车间培训模拟中有一位 NPC 安全讲师，负责讲解操作流程。这个角色需要权威、克制的手势，以展现自信而不显得分散注意力。

**设置（仅 Inspector）：**

1. 分配 `ConvaiSamplesShared_DialogAnimationLib_Balanced` 到 **库**
2. 将 Balanced `DialogueAnimationRuntimeConfig` 到 **配置**
3. 设置 **Character Gender** 到 **Male**

Balanced 库包含亲和度分布较低的片段， `EmotionBiasStrength` 从而生成一致的手势风格，不受检测到的情绪影响。这适合以教学为主、可预测性比表现力更重要的内容。

**预期结果：** 讲师会播放稳定的待机循环，并在讲话时切换到克制的手势片段。片段转换是渐进式的（默认 0.95 秒交叉淡化）。每次发言结束后，talk 层会平滑淡出。

***

### 示例 2 — 医疗患者演员

**场景：** 医疗模拟中有一名患者角色，起初以受控的动作（躺在医院病床上）开始问诊，随着焦虑上升变得更具表现力。手势库必须在运行时根据叙事触发器进行切换。

**设置：**

先使用 Subtle 库进行 Inspector 配置：

1. 分配 `ConvaiSamplesShared_DialogAnimationLib_Subtle` 到 **库**
2. 将 Subtle 配置分配给 **配置**
3. 设置 **Character Gender** 到 **Female**

然后在焦虑事件触发时，通过 C# 切换到 Expressive 库：

```csharp
using Convai.Modules.DialogueAnimation.Components;
using Convai.Modules.DialogueAnimation.Core;
using UnityEngine;

public class PatientAnimationController : MonoBehaviour
{
    [SerializeField] private ConvaiDialogueAnimationController _animController;
    [SerializeField] private DialogueAnimationLibrary _anxiousLibrary;

    public void OnAnxietyEventTriggered()
    {
        _animController.SetLibrary(_anxiousLibrary);
    }
}
```

**预期结果：** 在平静的问诊阶段，角色使用克制的待机和对话片段。之后 `OnAnxietyEventTriggered()` 被触发后，手势会在下一次片段选择周期中立即切换到更具表现力的片段池。不会重启或中断——交叉淡化会处理这一过渡。

***

### 示例 3 — 多角色企业入职引导

**场景：** 企业入职引导模拟中有两名讲师角色并排站立：一名资深，一名新手。它们共享相同的 `DialogueAnimationRuntimeConfig` 以保持时间一致性，但使用不同的库和性别设置来创建各自独特的视觉个性。

**关于片段选择的多样性：** 为了防止两个角色在同一帧选择到相同的片段，请在 `DeterministicSeed` 为每个角色的配置资源在 Inspector 中设置不同的值。 `DeterministicSeed` 是在制作时按资源配置的——不能通过脚本 API 设置。

**设置：**

创建两个 `DialogueAnimationRuntimeConfig` 资源（或复制一个）。在 Inspector 中，为每个资源设置不同的 `DeterministicSeed` 值。然后为每个角色分别分配：

```csharp
using Convai.Modules.DialogueAnimation.Components;
using Convai.Modules.DialogueAnimation.Runtime;
using UnityEngine;

public class MultiCharacterAnimationSetup : MonoBehaviour
{
    [SerializeField] private ConvaiDialogueAnimationController _seniorInstructor;
    [SerializeField] private ConvaiDialogueAnimationController _juniorInstructor;
    // 在 Inspector 中分配两个独立的配置资源——
    // 它们在制作时分别设置了不同的 DeterministicSeed 值。
    [SerializeField] private DialogueAnimationRuntimeConfig _seniorConfig;
    [SerializeField] private DialogueAnimationRuntimeConfig _juniorConfig;

    private void Start()
    {
        _seniorInstructor.SetConfig(_seniorConfig);
        _juniorInstructor.SetConfig(_juniorConfig);
    }
}
```

为每个角色设置不同的库：

* 资深： `ConvaiSamplesShared_DialogAnimationLib_Balanced`，Gender = Female
* 新手： `ConvaiSamplesShared_DialogAnimationLib_Expresive`，Gender = Male

**预期结果：** 两个角色都以相同的交叉淡化时长和能量响应（共享时间配置）进行动画，但使用不同的片段池和按性别筛选的选择，因此即使同时说话，看起来也各不相同。

***

### 示例 4 — 自适应评估模式

**场景：** 军事训练模拟有两个阶段：轻松的学习阶段和正式的评估阶段。在评估期间，NPC 评估员的动画风格必须改变，以体现评估的严肃性——更短的待机停留、更快的过渡、更正式的手势。

**设置：**

编写两个配置：

* `RelaxedConfig` — `IdleMinHoldSeconds: 8`, `IdleMaxHoldSeconds: 20`, `TalkCrossFadeDuration: 0.75`
* `AssessmentConfig` — `IdleMinHoldSeconds: 3`, `IdleMaxHoldSeconds: 8`, `TalkCrossFadeDuration: 0.4`

在阶段变化时通过 C# 切换：

```csharp
using Convai.Modules.DialogueAnimation.Components;
using Convai.Modules.DialogueAnimation.Runtime;
using UnityEngine;

public class AssessmentPhaseController : MonoBehaviour
{
    [SerializeField] private ConvaiDialogueAnimationController _evaluator;
    [SerializeField] private DialogueAnimationRuntimeConfig _relaxedConfig;
    [SerializeField] private DialogueAnimationRuntimeConfig _assessmentConfig;

    public void BeginAssessmentPhase()
    {
        _evaluator.SetConfig(_assessmentConfig);
    }

    public void BeginLearningPhase()
    {
        _evaluator.SetConfig(_relaxedConfig);
    }
}
```

**预期结果：** 在学习阶段，评估员的待机动画以较为轻松的节奏变化，停留时间较长。当 `BeginAssessmentPhase()` 被调用时，待机切换会更频繁，过渡更快，角色的手势节奏传达出更强的审视感——而无需对对话或会话逻辑进行任何代码更改。

***

### 下一步

有关完整的属性和方法参考，请参阅 Scripting API 页面。有关静默 talk 层或缺失动画等常见故障的帮助，请参阅故障排除。

{% content-ref url="/pages/9be0dcfc097dc8444409730b1036b4a2f70ec112" %}
[对话动画脚本 API](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/utilities/dialogue-animation/scripting-api.md)
{% endcontent-ref %}

{% content-ref url="/pages/0701ede6b3c4cdf57154ba57ba35ff6bd82a86bf" %}
[对话动画故障排除](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/utilities/dialogue-animation/troubleshooting.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:

```
GET https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/utilities/dialogue-animation/usage-examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
