> 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/adding-narrative-design-to-your-character.md).

# 为你的角色添加叙事设计

按照本指南将叙事设计整合到由 Convai 驱动的角色中。跟随这个分步教程，打开你的项目，让我们开始吧！

## Convai Playground

### 步骤 1：选择要启用叙事设计的角色

{% hint style="info" %}
在本演示中，我们使用 `Seraphine Whisperwind`，你也可以选择要启用叙事设计的任意角色。
{% endhint %}

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FVdP9GA4YFoyzj25J57gY%2FScreenshot%202024-05-22%20114710.png?alt=media&amp;token=4e3ae8cb-24a2-43a6-aea1-493eec6a43b8" alt=""><figcaption><p>显示在 <a href="#convai-playground">Convai Playground</a></p></figcaption></figure>

### 步骤 2：在 Convai Playground 中打开叙事设计

在侧边栏中选择“叙事设计”选项，然后创建叙事设计

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FWUsVhaveSrL4Bicq0rjl%2FScreenshot%202024-05-22%20115450.png?alt=media&amp;token=60d16d33-b3bf-4649-b494-6f00e1f8f8e6" alt=""><figcaption><p>显示叙事设计图标的截图</p></figcaption></figure>

{% hint style="info" %}
如需了解如何在 [Convai Playground](#convai-playground) 中创建叙事设计，请参阅以下 YouTube 视频系列
{% endhint %}

{% embed url="<https://www.youtube.com/playlist?list=PLn_7tCx0Chip2mfSbOkqJLevEbm3jDuNV>" %}
介绍如何创建叙事设计的视频系列
{% endembed %}

在此示例中，我们创建了以下叙事设计

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F5tzquGELWBGHWJ43qoXz%2FScreenshot%202024-05-23%20123350.png?alt=media&amp;token=232fcc89-7a66-48e1-a4cd-235c0845b9ab" alt=""><figcaption></figcaption></figure>

现在一切就绪，可以将角色从 Convai Playground 导入 Unity。接下来让我们转到 Unity，继续本指南。

## Unity 设置

### 步骤 1：添加 Narrative Design Manager 组件

#### 使用 <mark style="color:绿色;">添加组件</mark> 按钮（推荐在 Convai NPC 中使用此方式）

#### **1:** 在场景中选择 Convai 角色，并在 Inspector 面板中找到 ConvaiNPC 组件。点击 <mark style="color:绿色;">**添加组件**</mark> 按钮

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F4zBy2JF14bAWLIxA4VwQ%2FScreenshot%202024-05-22%20122312.png?alt=media&amp;token=6407ad84-8bd0-4baa-9c44-46812559756d" alt=""><figcaption><p>显示 <mark style="color:绿色;">添加组件</mark> 按钮在 Convai NPC 检视面板中的位置的截图</p></figcaption></figure>

#### **2:** 选中 **Narrative Design Manager** 复选框，然后点击 <mark style="color:绿色;">应用更改</mark> 按钮

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FFCZENWMKDxJenEm8o2EC%2FND%20Component%20Selected.png?alt=media&amp;token=fd65decb-47d2-4608-b1db-6ac26280b8e3" alt=""><figcaption><p>显示在“添加组件”窗口中选择叙事设计选项的截图</p></figcaption></figure>

#### 使用 Unity 检视面板

#### **1:** 选择 Convai 角色，并在检视面板中找到“添加组件”按钮

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FKk7vHnoMKaR6KLS5ZOwK%2FScreenshot%202024-05-22%20122424.png?alt=media&amp;token=eb3d954f-8a02-4bd0-89c1-8afb50505781" alt=""><figcaption><p>显示“添加组件”按钮在检视面板中位置的截图</p></figcaption></figure>

#### 2：在搜索框中搜索 `Narrative Design Manager` 并选择它

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2Fhr1IvEHvkCGO8Yb0dCBa%2FND%20Component%20Selected.png?alt=media&amp;token=ad8a5c2d-91ee-45e1-9e8e-462233bb0041" alt=""><figcaption><p>显示应从搜索结果中选择哪个组件的截图</p></figcaption></figure>

### 步骤 2：设置叙事设计组件

添加叙事设计组件后，你将看到以下组件

{% hint style="danger" %}
此组件系统假定 API 密钥已正确设置，因此请确保 API 密钥设置正确，否则将会报错。
{% endhint %}

{% hint style="info" %}
添加组件后，它会从 ConvaiNPC 中获取角色 ID，并检索该角色的各个章节。请根据网络速度稍作等待。
{% endhint %}

{% hint style="warning" %}
以下章节事件对应于演示中使用的角色。对于启用了叙事设计的角色，你会看到与该角色对应的章节事件。
{% endhint %}

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FfPrIoRevibp7ye3af1AL%2FScreenshot%202024-05-22%20122537.png?alt=media&amp;token=844b77bb-3c39-4d4b-a50b-88e4a1fb54f6" alt=""><figcaption><p>显示叙事设计组件示例的截图</p></figcaption></figure>

### 了解叙事设计组件

展开章节事件后，你会看到两个可供订阅的 Unity 事件：一个在章节开始时触发，另一个在章节结束时触发

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F58ErHzz6smZH2mjw96Pd%2FScreenshot%202024-05-22%20143301.png?alt=media&amp;token=449d222b-1bc4-4b76-a196-cabe0500b3a8" alt=""><figcaption><p>显示用户可订阅的各种 Unity 事件的截图</p></figcaption></figure>

### 了解章节触发器

章节触发器可直接调用叙事设计中的某个章节，也可用于跳转到叙事设计中的其他章节

#### 步骤 1：选择要设置为触发器的游戏对象。本例中选择了一个简单的立方体，当然也可以发挥你的想象。

{% hint style="info" %}
确保你选作触发器的游戏对象附加了碰撞体
{% endhint %}

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F54r8jK8GnnDwRsJ8or25%2FScreenshot%202024-05-22%20144701.png?alt=media&amp;token=11f18709-6261-464f-a0b4-9f9ac6c75506" alt=""><figcaption><p>显示已选中并附加碰撞体的游戏对象的截图</p></figcaption></figure>

#### 步骤 2：在“添加组件”菜单中搜索并添加“叙事设计触发器”

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FORJZh5Z0MpUTwi6XDgwH%2FScreenshot%202024-05-22%20145128.png?alt=media&amp;token=307764c7-3cdb-4553-a4e7-58e85d7a3ae1" alt=""><figcaption><p>显示选择“叙事设计触发器”的截图</p></figcaption></figure>

#### 步骤 3：将碰撞体设为触发器。

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F3vLmpGnjDerqXnZUnTSI%2FScreenshot%202024-05-22%20145314.png?alt=media&amp;token=618e67d1-c3a1-4615-b055-042848717980" alt=""><figcaption><p>显示将盒体碰撞器设为触发盒的截图</p></figcaption></figure>

#### 步骤 4：将 Convai NPC 指定到 Convai NPC 字段

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F6HVQ1IwrEnZWAtU8NOKk%2FScreenshot%202024-05-22%20145631.png?alt=media&amp;token=f35d8e8a-2605-49c6-8b8d-86fdcb35f3de" alt=""><figcaption><p>显示将 Convai NPC 指定给触发器组件的截图</p></figcaption></figure>

现在，你可以在“触发器”下拉菜单中选择玩家进入此触发盒时要调用的触发器。

我们还添加了手动调用此触发器的功能，你可以使用 `InvokeSelectedTrigger` 函数，从任意位置调用该触发器

<figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2F6UGCfq75lseBK1dL5AUZ%2FScreenshot%202024-05-23%20123713.png?alt=media&amp;token=c6a64b74-2cca-4b78-b518-b301d92d71ff" alt=""><figcaption><p>显示如何选择所需触发器的截图</p></figcaption></figure>

### 从任意脚本调用触发器

你可以参考以下代码块，从任意位置调用触发器

```csharp
if(convaiNPC.TryGetComponent(out NarrativeDesignTrigger narrativeDesignTrigger))
{
    //如果希望调用触发器时发送消息，可使用可选的消息参数
    //触发器 
    string message = "Player has collected enough resources";
    narrativeDesignTrigger.InvokeSelectedTrigger(message);
}
```


---

# 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/adding-narrative-design-to-your-character.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.
