For the complete documentation index, see llms.txt. This page is also available as Markdown.

叙事设计快速开始

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

本指南将带你走完搭建可用的 Narrative Design 设置的最快路径。到最后,当玩家穿过一个触发区域时,角色会对章节切换作出反应——完全通过 Inspector 完成,无需任何代码。

前提条件

开始前,请确认:

设置管理器和触发器

1

添加 Narrative Design Manager

选择包含你的 ConvaiCharacter 组件的 GameObject。在 Inspector 中,点击 添加组件 并搜索 Narrative Design Manager (路径: Convai > Narrative Design Manager).

管理器会自动检测 ConvaiCharacter 位于同一个 GameObject 上。如果你的角色位于不同的 GameObject 上,请将其拖入 角色 字段中。

ConvaiNarrativeDesignManager added to the character GameObject in the Unity Inspector
角色的 GameObject 上的 ConvaiNarrativeDesignManager。
2

从仪表板同步章节

在管理器的 Inspector 中,点击 与后端同步。SDK 会获取你的叙事章节并填充 叙事章节 列表。每个条目显示来自仪表板的章节名称。

如果列表仍为空,请确认角色 ID 已设置在 ConvaiCharacter 并且你的 API 密钥有效——请参见 配置 API 密钥。该 最后一次获取错误 字段会在出错时显示具体错误。

Narrative Sections list populated after clicking Sync with Backend
成功同步后的 Narrative Sections 列表。
3

连接章节事件

展开第一个章节条目 叙事章节 列表。你会看到两个 Unity Event: 章节开始时 和 章节结束时.

点击 + 时 章节开始时,将任意 GameObject 拖到对象字段中,并选择要调用的方法。用于测试的最简单选项是 NarrativeDesignDebugLogger 下面的辅助脚本——将其添加到任意 GameObject,将该 GameObject 拖入监听器字段,并选择 NarrativeDesignDebugLogger.LogSectionStarted.

NarrativeDesignDebugLogger.cs
using UnityEngine;

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

    /// 连接到 UnitySectionEventConfig.OnSectionStart Unity 事件。
    public void LogSectionStarted()
    {
        Debug.Log($"[NarrativeDesign] {_label} 已开始。", this);
    }

    /// 连接到 ConvaiNarrativeDesignManager.OnAnySectionChanged Unity 事件。
    /// 以字符串形式接收新的章节 ID。
    public void LogSectionChanged(string sectionId)
    {
        Debug.Log($"[NarrativeDesign] 章节已更改 → {sectionId}", this);
    }
}
On Section Start Unity Event wired to a debug logger component
On Section Start 已连接到 NarrativeDesignDebugLogger。
4

添加 Narrative Design Trigger

在场景中创建一个新的空 GameObject,并将其放置在玩家会经过的位置。点击 添加组件 并搜索 Convai Narrative Design Trigger (路径: Convai > Convai Narrative Design Trigger).

将你的 ConvaiCharacter 将第二个角色自己的 Character ID 从 角色 字段拖入其中,或者将其留空,让 自动查找角色 自动定位。

ConvaiNarrativeDesignTrigger added to an empty GameObject in the scene
将 ConvaiNarrativeDesignTrigger 添加到一个世界空间触发器 GameObject 上。
5

获取并选择一个触发器

在 Trigger 组件的 Inspector 中,点击 获取 以从仪表板加载命名触发器。会出现一个下拉菜单——选择应将图推进到你的第一个章节的触发器。

Trigger Selection dropdown populated after clicking Fetch
从 Convai 仪表板填充的触发器下拉菜单。
6

添加碰撞器

默认激活模式是 碰撞,它使用 Unity 的 OnTriggerEnter。在同一个触发器 GameObject 上,点击 添加组件 > Box Collider。在 Box Collider 的设置中,启用 Is Trigger.

调整碰撞器大小,使其覆盖你希望触发器生效的区域。在 Scene 视图中,绿色线框盒显示检测区域。

Box Collider with Is Trigger enabled on the trigger zone GameObject
已启用 Is Trigger 的 Box Collider。
7

点击 Play,并穿过

进入 Play Mode,并让玩家穿过碰撞器区域。

该设置产生了什么

穿过碰撞器区域后,完整的 Narrative Design 流程被激活:

“ ConvaiNarrativeDesignTrigger 通过……检测到玩家 OnTriggerEnter 并调用了 InvokeTrigger() ,使用你选择的触发器名称。SDK 会将该触发器排队,直到角色的实时会话打开,然后发送一个 trigger-message 通过 RTVI 连接发送到 Convai。Convai 沿匹配的边推进叙事图,并返回一个 behavior-tree-response ,其中包含新的章节 ID。 ConvaiNarrativeDesignManager 将该章节 ID 与其本地列表进行匹配,并触发了 OnSectionStart 匹配条目上的

有关此流程的完整说明,请参见 叙事设计的工作原理.

下一步

配置叙事设计管理器配置叙事设计触发器配置叙事模板键

最后更新于

这有帮助吗?