> 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 Playground

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

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

<figure><img src="/files/a78684c6e10b2d35ed910140fa25957698c16a4f" alt=""><figcaption><p>显示选择角色的截图 <a href="#convai-playground">Convai Playground</a></p></figcaption></figure>

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

从侧边栏中选择叙事设计选项并创建你的叙事设计

<figure><img src="/files/f826fbfbcd2c78bb3dd04c739a6b86966a61e3e2" 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="/files/4e1fcd42c327173d5f8fa569300d52f7618f9a3f" alt=""><figcaption></figcaption></figure>

你已经准备好将你的角色从 Convai Playground 带到 Unity 了，让我们前往 Unity 继续本指南

## Unity 设置

### 步骤1：添加叙事设计管理器组件

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

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

<figure><img src="/files/c6994f52df5804245f502ab20074c175f6cd775b" alt=""><figcaption><p>显示……位置的截图 <mark style="color:绿色;">添加组件</mark> Convai NPC 检查器面板中的按钮</p></figcaption></figure>

#### **2:** 选择 **叙事设计管理器** 复选框，然后点击 <mark style="color:绿色;">应用更改</mark> 按钮

<figure><img src="/files/29e3e125abdcca187dca1fd60b91214ea9a00753" alt=""><figcaption><p>显示在添加组件窗口中选择叙事设计选项的截图</p></figcaption></figure>

#### 使用 Unity 检查器

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

<figure><img src="/files/4f07c959266aa2663c19e330dab5ab40a51fc49c" alt=""><figcaption><p>显示检查器面板中“添加组件”按钮位置的截图</p></figcaption></figure>

#### 2：搜索 `叙事设计管理器` ，在搜索框中并选择它

<figure><img src="/files/c2b400ac0c1b9eeb9ad722694553f6797fd559d8" 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="/files/443c076e082b36977b71773fdf1f0a4240987059" alt=""><figcaption><p>显示示例叙事设计组件的截图</p></figcaption></figure>

### 了解叙事设计组件

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

<figure><img src="/files/29fd2307747b73a055f48285cf6ab7fc15052abc" alt=""><figcaption><p>显示用户可订阅的各种 Unity 事件的截图</p></figcaption></figure>

### 了解章节触发器

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

#### 步骤1：选择你想要作为触发器的游戏对象，在这个示例中我们选择了一个简单的立方体，但这取决于你的想象力。

{% hint style="info" %}
确保你决定作为触发器的游戏对象附带一个碰撞体
{% endhint %}

<figure><img src="/files/6c8de8b76b195647cbd6dc2167356686e457bfff" alt=""><figcaption><p>显示已选中带有碰撞体的游戏对象的截图</p></figcaption></figure>

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

<figure><img src="/files/d75759f6cc20542531c45beb6c6be4635c65fc63" alt=""><figcaption><p>显示选择叙事设计触发器的截图</p></figcaption></figure>

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

<figure><img src="/files/b62a25ca32479760402947176951778d20821975" alt=""><figcaption><p>显示 Box Collider 变为触发框的截图</p></figcaption></figure>

#### 步骤4：将你的 Convai NPC 分配到 Convai NPC 字段

<figure><img src="/files/17b961a3d4043bcdb322712a571e85889c85ee54" alt=""><figcaption><p>显示将 Convai NPC 分配给触发器组件的截图</p></figcaption></figure>

现在你可以在“Trigger”下拉菜单中选择当玩家进入此触发框时应调用哪个触发器。

我们还为你添加了一种手动调用此触发器的方法，你可以使用 `InvokeSelectedTrigger` 函数从任何地方调用该触发器

<figure><img src="/files/da54c20e1ad6267559c23549683af1968c2cdcce" alt=""><figcaption><p>显示可选择你所需触发器的截图</p></figcaption></figure>

### 从任何脚本中调用触发器

你可以将此代码块作为参考，从任何地方调用触发器

```csharp
if(convaiNPC.TryGetComponent(out NarrativeDesignTrigger narrativeDesignTrigger))
{
    //可选消息参数，如果你在调用时想发送一些消息
    //该触发器 
    string message = "玩家已收集到足够的资源";
    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 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/unity-plugin/adding-narrative-design-to-your-character.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.
