> 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/narrative-design/quick-start.md).

# 叙事设计快速开始

向 Convai 角色添加 Narrative Design Manager 和碰撞触发器，并在播放模式下确认章节切换——无需代码。

本指南将带你以最快的方式搭建可用的 Narrative Design 环境。完成后，玩家穿过触发区域时，角色会对区段切换做出反应——整个过程只需在 Inspector 中操作，无需编写代码。

### 前提条件

开始之前，请确认：

* [ ] 一个 `ConvaiCharacter` 位于场景中，并且已在 Inspector 中设置其 Character ID
* [ ] 至少为该角色定义了一个区段和一个触发器，位置在 [Convai 控制面板](https://convai.com)

### 设置管理器和触发器

{% stepper %}
{% step %}

#### 添加 Narrative Design Manager

选择包含 `ConvaiCharacter` 组件的 GameObject。在 Inspector 中，点击 **添加组件** 并搜索 **Narrative Design Manager** （路径： **Convai > Narrative Design Manager**).

Manager 会自动检测同一 GameObject 上的 `ConvaiCharacter` 。如果角色位于其他 GameObject 上，请将其拖到 **Character** 字段中。

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FFwSbVyP7YFCNjTUn0dCE%2Fimage.png?alt=media&amp;token=709232fe-2eb5-4a09-adc8-8aad87697595" alt="ConvaiNarrativeDesignManager added to the character GameObject in the Unity Inspector"><figcaption><p>角色 GameObject 上的 ConvaiNarrativeDesignManager。</p></figcaption></figure>
{% endstep %}

{% step %}

#### 从控制面板同步区段

在 Manager 的 Inspector 中，点击 **与后端同步**。SDK 会获取你的叙事区段，并填充 **叙事区段** 列表。每个条目都会显示该区段在控制面板中的名称。

如果列表仍为空，请确认已在 `ConvaiCharacter` 上设置角色 ID，并且 API 密钥有效——请参阅 [配置 API 密钥](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/getting-started/configure-api-key.md)。如果出现问题， **上次获取错误** 字段会显示具体错误。

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FMMpzUWLNUV3t2hE2J8MY%2Fimage.png?alt=media&amp;token=ac3c38cb-d2bc-46ad-8e62-b3fe8c31ec52" alt="Narrative Sections list populated after clicking Sync with Backend"><figcaption><p>成功同步后的叙事区段列表。</p></figcaption></figure>
{% endstep %}

{% step %}

#### 关联区段事件

展开 **叙事区段** 列表中的第一个区段条目。你会看到两个 Unity 事件： **区段开始时** 和 **区段结束时**.

点击 **+** 旁边的 **区段开始时**，将任意 GameObject 拖到对象字段中，然后选择要调用的方法。最简单的测试方式是使用下方的 `NarrativeDesignDebugLogger` 辅助脚本——将它添加到任意 GameObject，将该 GameObject 拖到侦听器字段中，然后选择 `NarrativeDesignDebugLogger.LogSectionStarted`.

<details>

<summary>NarrativeDesignDebugLogger.cs</summary>

```csharp
using UnityEngine;

public class NarrativeDesignDebugLogger : MonoBehaviour
{
    [SerializeField] private string _label = "Section";

    /// 关联到 UnitySectionEventConfig.OnSectionStart Unity 事件。
    public void LogSectionStarted()
    {
        Debug.Log($"[NarrativeDesign] {_label} started.", this);
    }

    /// 关联到 ConvaiNarrativeDesignManager.OnAnySectionChanged Unity 事件。
    /// 接收作为字符串的新章节 ID。
    public void LogSectionChanged(string sectionId)
    {
        Debug.Log($"[NarrativeDesign] Section changed → {sectionId}", this);
    }
}
```

</details>

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FJCDELFWjkp0sn7em2vnB%2Fimage.png?alt=media&amp;token=d15e8f05-2442-474e-b3be-7bb4120c217f" alt="On Section Start Unity Event wired to a debug logger component"><figcaption><p>已将“章节开始”关联到 NarrativeDesignDebugLogger。</p></figcaption></figure>
{% endstep %}

{% step %}

#### 添加叙事设计触发器

在场景中创建一个新的空 GameObject，并将其放置在玩家会经过的位置。点击 **添加组件** 并搜索 **Convai 叙事设计触发器** （路径： **Convai > Convai 叙事设计触发器**).

将你的 `ConvaiCharacter` 拖到 **角色** 字段中，或者留空以便让 **自动查找角色** 自动定位角色。

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FYOIcr50hHQ3kSpqPbJMY%2Fimage.png?alt=media&amp;token=67a0393f-25d4-47c0-9063-ece1d3d210cf" alt="ConvaiNarrativeDesignTrigger added to an empty GameObject in the scene"><figcaption><p>World Space 触发器 GameObject 上的 ConvaiNarrativeDesignTrigger。</p></figcaption></figure>
{% endstep %}

{% step %}

#### 获取并选择触发器

在触发器组件的检查器中，点击 **获取** 以从控制面板加载已命名的触发器。此时会出现一个下拉菜单——选择应当使图形前进到第一个章节的触发器。

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FEqHSckjPlBbbfdgbpdgE%2Fimage.png?alt=media&amp;token=80be2bb4-5692-467c-bda9-3b63bdbe192c" alt="Trigger Selection dropdown populated after clicking Fetch"><figcaption><p>已从 Convai 控制面板填充触发器下拉菜单。</p></figcaption></figure>
{% endstep %}

{% step %}

#### 添加碰撞体

默认激活模式为 **碰撞**，使用 Unity 的 `OnTriggerEnter`。在同一个触发器 GameObject 上，点击 **添加组件 > 盒体碰撞体**。在盒体碰撞体的设置中，启用 **Is Trigger**.

调整碰撞体大小，使其覆盖你希望触发器触发的区域。在场景视图中，绿色线框框显示检测区域。

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FXKbHie3bmpbDUrkbHuRz%2Fimage.png?alt=media&amp;token=3fa6282e-e193-4c71-a081-6804ed4dd16a" alt="Box Collider with Is Trigger enabled on the trigger zone GameObject"><figcaption><p>已启用 Is Trigger 的盒体碰撞体。</p></figcaption></figure>
{% endstep %}

{% step %}

#### 按下 Play 并走过触发区域

{% hint style="warning" %}
**玩家设置检查清单——按下 Play 前确认以下三项：**

* **标签：** 玩家 GameObject 的标签必须设置为 `Player`。触发器组件会通过标签匹配来识别玩家。
* **碰撞体：** 玩家必须具有碰撞体组件。否则， `OnTriggerEnter` 将永远不会触发。
* **刚体：** 触发器区域或玩家必须有一个 `Rigidbody`。将它添加到玩家身上——如果添加到触发器区域，则必须为场景中的每个触发器对象重复此操作。

缺少其中任何一项，都是在 Play Mode 中触发器看似毫无反应的最常见原因。
{% endhint %}

进入 Play Mode，让玩家穿过碰撞体区域。

{% hint style="success" %}
玩家进入区域时，Console 中会显示区段 ID。角色的下一条回复会体现新区段的目标。
{% endhint %}
{% endstep %}
{% endstepper %}

### 此设置的效果

玩家穿过碰撞体区域后，完整的叙事设计流程便会启动：

&#x20;`ConvaiNarrativeDesignTrigger` 通过 `OnTriggerEnter` 检测到玩家，并调用 `InvokeTrigger()` ，传入你选择的触发器名称。SDK 会将触发器排入队列，直到角色的实时会话开启，然后通过 RTVI 连接向 Convai 发送 `trigger-message` 。Convai 会沿着匹配的边推进叙事图，并返回一个包含新区段 ID 的 `behavior-tree-response` 。 `ConvaiNarrativeDesignManager` 会将该区段 ID 与本地列表进行匹配，并在匹配的条目上触发 `OnSectionStart` 。

如需全面了解此流程，请参阅 [叙事设计的工作原理](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/narrative-design/how-narrative-design-works.md).

### 后续步骤

{% content-ref url="/pages/59d31b624a51d8790cd9e50732a32794dcfd69f1" %}
[配置叙事设计管理器](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/narrative-design/setting-up-the-narrative-design-manager.md)
{% endcontent-ref %}

{% content-ref url="/pages/87ddb3e30dd1b009eb7bf39b583b5a654f486dbb" %}
[配置叙事设计触发器](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/narrative-design/setting-up-narrative-design-triggers.md)
{% endcontent-ref %}

{% content-ref url="/pages/630c1743293b81e62f2237b571dcf928c0d73285" %}
[配置叙事模板键](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/narrative-design/template-keys-dynamic-narrative-variables.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/features/narrative-design/quick-start.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.
