Home

Awesome

Next Gen Dialogue User Manual

<img src="Docs/Images/Splash.png" >

Read this document in Chinese: 中文文档

Content

Features

<Img src = "Docs/Images/BakeDialogue.png">

Next Gen Dialogue plugin is a Unity dialogue plugin combined with large language model design, won the Unity AI Plugin Excellence Award from Unity China. It combines the traditional dialogue design method with AI technique. Currently this package is an experimental attempt and hopes you enjoy it.

It has the following features:

  1. Visual dialogue editor
  2. Modular dialogue function
  3. Support AIGC baking dialogue in Editor
  4. Debug during runtime

Demo project: https://github.com/AkiKurisu/Next-Gen-Dialogue-Example-Project

<Img src = "Docs/Images/DemoExample2.png"> <Img src = "Docs/Images/DemoExample1.png">

Demo video: https://www.bilibili.com/video/BV1hg4y1U7FG

<Img src = "Docs/Images/BilibiliDemo.png">

Supported version

Install

Using git URL to download package by Unity PackageManager https://github.com/AkiKurisu/Next-Gen-Dialogue.git

The experimental features of Next Gen Dialogue are placed in the Modules folder and will not be enabled without installing the corresponding dependencies. You can view the dependencies in the README.md document under its folder.

To use core functions, you need to install Newtonsoft Json in PackageManager.

Quick Start

If you are using this plugin for the first time, it is recommended to play the following example scenes first:

1.Normal Usage.unity this scene contains the use of NextGenDialogueTree and NextGenDialogueTreeSO;

2. Editor Bake Dialogue.unitythis scene contains the sample of baking conversation conversation in the use of AI dialogue Baker in Editor;

3.Build Dialogue by Code.unity this scene contains the use of Code to generate dialogue.

4.Bake Novel.unity An example of using ChatGPT to infinitely generate dialogue trees.

Create a Dialogue Tree

NextGenDialogueTree and NextGenDialogueTreeSO are used to store dialogue data. In order to facilitate understanding, it is collectively referred to as dialogue tree. The following process is to create a dialogue tree that contains only a single dialogue and a single option:

  1. Mount NextGenDialogueTree on any gameObject

  2. Click Edit DialogueTree to enter the editor

  3. Create the Container/dialogue node, the node is the dialogue container used in the game

  4. Connect the Parent port of the dialogue Node to the root node. You can have multiple dialogue in one dialogueTree, but only those connected to the root node will be used.

  5. Create the Container/Piece node and create our first dialogue fragment

  6. Right -click Piece node Add Module add Content Module, you can fill in the contents of the conversation in Content

  7. Create a Container/Option node and create a dialogue option corresponding to the PIECE node

  8. Right-click Piece node Add Option, connect Piece with Option

  9. <b style = "color:#ee819e"> Very important: </b> At least one Piece node needs to be added to the Dialogue as the first piece of the dialogue.You can right -click dialogue's Add Piece to connect with the connection or quoting its PieceID. You can also right -click dialogue's Collect All Pieces to add all the piece in Graph to the dialogue and adjust the priority of the Piece

    <Img src = "Docs/Images/CreateDialogue.png">
  10. Click on the upper left of the editor's Save to save dialogue

  11. Click Play to enter PlayMode

  12. Click on NextGenDialogueTree Play dialogue to play conversation

  13. Click Debug DialogueTree to enter the debug mode

<IMG SRC = "Docs/Images/RuntimeDebug.png">

AI Bake Dialogue

You can use AI dialogue Baker to bake the dialogue content generated by AI in advance when designing the dialogue tree, so as to improve the workflow efficiency without affecting your design framework.

<img src="Docs/Images/BakeDialogue.png">
  1. The basic dialogue tree design is consistent with the process of 《Create a Dialogue Tree》
  2. Add AI Bake Module for the fragments or options that need to be baked, and remove the module for nodes that do not need to be baked
  3. Select the type of LLM you are baking with
  4. <b>Select in turn</b> the nodes that AI dialogue Baker needs to recognize, the order of recognition is based on the order selected by the mouse, and finally select the nodes that need to be baked
  5. If the selection is successful, you can see the preview input content at the bottom of the editor
  6. Click the Bake Dialogue button on the AI Bake Module and wait for the AI response
  7. After the language model responds, a Content Module will be automatically added to the node to store the baked dialogue content
  8. You can continuously generate conversations based on your needs

AI Generate Novel

Different from talking directly to AI in baking dialogue, novel mode allows AI to play the role of copywriter and planner to write dialogue, so it can control options and fragments more precisely. Please refer to the example: 4.Bake Novel.unity

<img src="Docs/Images/BakeNovel.png" >

Nodes

NGD use node based visual editor framework, most of the features are presented through nodes.

The construction dialogue are divided into the following parts in NGD:

NameDescription
DialogueUsed to define dialogues, such as the first piece of the dialogue and other attributes
Piecedialogue piece, usually store the core dialogue content
Optiondialogue options, usually used for interaction and bridging dialogues

In addition, in order to add interest to the dialogue such as adding events and executing actions, you can use the following types of nodes in the behavior tree framework in NGD:

NameDescription
CompositeIt has one or more child nodes and controls which child nodes are updated.
ActionThis is a leaf node. It performs actions such as following the player, attacking, fleeing or other actions you define.
ConditionalIt has a child node and checks if the child node is updatable. When there is no child node, Conditional is a leaf node like Action.
DecoratorIt has a child node, which will modify the return value according to the return value of the child node

Modules

In addition to the above nodes, a more flexible concept is used in NGD, that is, Module. You can use Module to change the output form of the dialogue, such as Google translation, localization, add callbacks, or be executed as a markup.

General Modules

The following are built-in general modules:

NameDescription
Content ModuleProvide text content for Option or Piece
TargetID ModuleAdd jumping target dialogue fragments for Option
PreUpdate ModuleAdd pre-update behavior for Container, it will update when jumping to the Container
CallBack ModuleAdd callback behavior for Option, they will be updated after selection
ScriptableEvent ModuleAdds ScriptableEvent events to Option, they will be updated after selection, ScriptableEvent can be used for cross-scenario event subscription
UnityEvent ModuleAdd UnityEvent events to Option, they will be updated after selection, UnityEvent can be used for event subscription in traditional single scene
Condition ModuleAdd judgment behavior for Option or Piece, it will be updated when jumping to the Container, if the return value is Status.Failure, the Container will be discarded. If it is the first Piece of the dialogue, the system will try to jump to the next Piece according to the order in which the Pieces are placed in the dialogue
NextPiece ModuleAdd the next dialogue segment after the end of the Piece. If there is no option, it will jump to the specified dialogue segment after playing the content of the Piece
Google Translate ModuleUse Google Translate to translate the content of current Option or Piece

AIGC Modules

The following are the built-in AIGC modules:

NameDescription
Prompt ModulePrompt words that provide the basis for subsequent dialogue generation

Experimental Modules

The following are experimental modules, you need to install the corresponding Package or configure the corresponding environment before use:

Localization Extension

Based on the UnityEngine.Localization plugin to support the localization of dialogue

NameDescription
Localized Content ModuleProvide content for Option or Piece after getting text from localization

VITS Speech Extension

For VITS local deployment, please refer to this repository: VITS Simple API

If you want to use the VITS module, please use it with VITSAIReResolver. For the use of the Resolver, please refer to the following 《Resolver》

NameDescription
VITS ModuleUse VITS speech synthesis model to generate language for Piece or Option in real time

Editor Function Introduction

One-click Translation

Add Editor/EditorTranslateModule in the Dialogue node, set the source language (sourceLanguageCode) and target language (targetLanguageCode) of the translation, right-click and select Translate All Contents to perform all Piece and Option with ContentModule translate.

<img src="Docs/Images/FastTranslation.png" >

For nodes other than ContentModule, if the TranslateEntryAttribute is added to the field, you can right-click a single node to translate it.

namespace Kurisu.NGDT.Behavior
{
    public class SetString : Action
    {
      //Notify field can be translated
      //* Only work for SharedString and string
      [SerializeField, Multiline, TranslateEntry]
      private SharedString value;
    }
}
<img src="Docs/Images/SingleTranslate.png" >

Bake Voice

Before use, you need to install the corresponding dependencies of Modules/VITS and open the local VITS server (refer to Modules/VITS/README.md). Add AIGC/VITSModule to the node where speech needs to be generated, right-click and select Bake Audio

<img src="Docs/Images/BakeAudio.png" >

If you are satisfied with the generated audio, click Download to save it locally to complete the baking, otherwise the audio file will not be retained after exiting the editor.

It is no longer necessary to start the VITS server at runtime after baking is complete.

Resolvers

Resolver is used to detect the Module in the Container at runtime and execute a series of preset logic such as injecting dependencies and executing behaviors, the difference between NGD's built-in Resolver is as follows:

NameDescription
Default ResolverThe most basic resolver, supporting all built-in common modules
VITS ResolverAdditionally detect VITS modules to generate voice in real time

How to Switch Resolver

  1. In-scene Global Resolver You can mount the VITSSetup script on any GameObject to enable AIResolver in the scene

  2. Dialogue specified Resolver

    You can add VITSResolverModule to the dialogue node to specify the resolver used by the dialogue, and you can also click the Setting button in the upper right corner of the module and select which Resolvers to be replaced in Advanced Settings

Create Dialogue by Code

NGD is divided into two parts, DialogueSystem (NGDS) and DialogueTree (NGDT). The former defines the data structure of the dialogue, which is interpreted by Resolver after receiving the data. The latter provides a visual editing solution and inherits the interface from the former. So you can also use scripts to write dialogues, examples are as follows:

using UnityEngine;
public class CodeDialogueBuilder : MonoBehaviour
{
    private DialogueBuilder builder;
    private IEnumerator Start()
    {
        yield return new WaitForEndOfFrame();
        PlayDialogue();
    }
    private void PlayDialogue()
    {
        var dialogueSystem = IOCContainer.Resolve<IDialogueSystem>();
        builder = new DialogueBuilder();
        //First Piece
        var piece = DialoguePiece.GetPooled();
        piece.Content = "This is the first dialogue piece";
        piece.PieceID = "01";
        piece.AddOption(new DialogueOption()
        {
            Content = "Jump to Next",
            TargetID = "02"
        });
        generator.AddPiece(piece);
        //Second Piece
        piece = DialoguePiece.GetPooled();
        piece.Content = "This is the second dialogue piece";
        piece.PieceID = "02";
        var callBackOption = DialogueOption.GetPooled();
        //Add CallBack Module
        callBackOption.AddModule(new CallBackModule(() => Debug.Log("Hello World !")));
        callBackOption.Content = "Log";
        piece.AddOption(callBackOption);
        generator.AddPiece(piece);
        dialogueSystem.StartDialogue(generator);
    }
}