# Narration System

{% hint style="info" %}
The Narration (dialogue) System allows you to define simple dialogues with subtitles that appear at the bottom of the screen, as you have seen in many other games.
{% endhint %}

{% hint style="warning" %}
This system is not a complete dialogue solution where you can talk to NPCs etc., but a system that allows you to display subtitles for dialogue at certain moments.
{% endhint %}

### Adding New Dialogues

1. Right-click on any project folder and select **Create -> UHFPS -> Dialogue -> Dialogue Asset**.
2. To add a new dialogue, click the **Add Dialogue** button and select the Dialogue 0.

<figure><img src="https://2665493337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh8bp6Jx5qkS4c0NEaWR1%2Fuploads%2FnawTN4Zuk4KcVF7nv14B%2FScreenshot_1.png?alt=media&#x26;token=3912fe97-d0bb-42fd-98d1-79165ed87520" alt=""><figcaption></figcaption></figure>

3. Assign a **Dialogue Audio**, this can be any audio that contains speech and for which you want to create subtitles.
4. You can select the type of subtitles the dialogue contains. You can select **Single** or **Multiple**.

{% hint style="info" %}
**Single**: Select this type if the dialogue audio contains only one sentence or word.

**Multiple**: Select this type if the dialogue audio contains many different sentences or pauses.
{% endhint %}

{% hint style="info" %}
If you have selected the option **Multiple**, you will have different options. For example, instead of having subtitle settings, you'll see an audio waveform where you can place subtitles at different points in the audio.
{% endhint %}

<figure><img src="https://2665493337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh8bp6Jx5qkS4c0NEaWR1%2Fuploads%2FsmMM9e442K3zfh1aTZ5S%2Fdialogue_1.png?alt=media&#x26;token=78d42039-afa8-4bef-94ef-82d7d0201543" alt=""><figcaption></figcaption></figure>

5. To add a new subtitle, click the **+Subtitle** button.

<figure><img src="https://2665493337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh8bp6Jx5qkS4c0NEaWR1%2Fuploads%2FGDnQHhZ8yIyjoD8NePbD%2Fdialogue_2.png?alt=media&#x26;token=b90aedc5-29a4-491c-b1f3-15e429bdb1f4" alt=""><figcaption></figcaption></figure>

6. You can also add breakpoints to hide the subtitle until the next subtitle appears. Click the **+Break** button to add a new breakpoint.

<figure><img src="https://2665493337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh8bp6Jx5qkS4c0NEaWR1%2Fuploads%2FzaGJDFG3CqEn953eeTHG%2Fdialogue_3.png?alt=media&#x26;token=d6533bdb-8253-4317-acf9-70f79d012694" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
You can move the subtitle by dragging the vertical white line to where you want the subtitle to appear.
{% endhint %}

{% hint style="danger" %}
To select the subtitle click on the button below the vertical line.
{% endhint %}

6. If you select subtitle, you can define subtitle settings such as who is speaking, the color of the narrator or the subtitle text.
7. To trigger a dialogue, create a new trigger object by enabling the **Is Trigger** option in the collider and add a **Dialogue Trigger** component to it.

<figure><img src="https://2665493337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh8bp6Jx5qkS4c0NEaWR1%2Fuploads%2F8pYVpUUP4RPderNCB6d7%2FScreenshot_5.png?alt=media&#x26;token=64459ff6-95dc-42a9-aea3-fcdab77ea2ee" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
In the component window you have several settings. The **Trigger Type** defines how you want the dialogue to be triggered. By a **Trigger**, **Interaction**, or by **Event**.
{% endhint %}

{% hint style="info" %}
The **Dialogue Type** defines where the dialogue audio will be played. Type **Local** means that the dialogue will be played locally as an NPC narration. Type **Global** means that the dialogue will most likely be played by the player.
{% endhint %}

{% hint style="info" %}
**Dialogue Continue** specifies how multiple dialogues will be treated. If you keep this in **Sequence**, the dialogues will be played one by one. If you set this to **Event**, the next dialogue will be played when you call `DialogueSystem.NextDialogue()`.&#x20;

**DialogueSystem** is a component that is added to the **GAMEMANAGER** object and it is **Singleton** so you can make easy calls.
{% endhint %}

### Dialogue Binder

{% hint style="info" %}
**Dialogue Binder** is a special feature that can be used in different ways. It can be used to display the current subtitle in world space or even to synchronize the NPC's mouth with the words.
{% endhint %}

{% hint style="info" %}
**Dialogue Binder** works by triggering certain events that are sent by the **Dialogue System**, so you can create custom things simply by registering the events you need.
{% endhint %}

1. To use the binder, add a **Dialogue Binder** component to your object.
2. To use binder events, you can create a new script that will have methods with the parameters specified in the event.

Here are the methods used to display the speech bubble dialogue:

```csharp
// will be called when the dialogue starts
public void OnDialogueStart(AudioSource _, string binderName)
{
    if(isPlaying = binderName == BinderName)
        TextMesh.gameObject.SetActive(true);
}

// will be called at every subtitle
public void OnSubtitle(AudioClip _, string subtitleText)
{
    if (!isPlaying)
        return;

    TextMesh.text = subtitleText;
}

// will be called at the end of the subtitle sequence
public void OnSubtitleFinish()
{
    if (!isPlaying || !HideBetweenSubtitles)
        return;

    TextMesh.text = "";
}

// will be called when the dialogue ends
public void OnDialogueEnd()
{
    if (!isPlaying)
        return;

    TextMesh.gameObject.SetActive(false);
    TextMesh.text = "";
    isPlaying = false;
}
```

{% hint style="info" %}
The events will be invoked in each **Dialogue Binder** component, so you need to check if the **binderName** is the one you want to use in the script.
{% endhint %}

3. Then you can register dialogue binder events on these methods

<figure><img src="https://2665493337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh8bp6Jx5qkS4c0NEaWR1%2Fuploads%2FlMazkVM5MwMrLuA4QopG%2FScreenshot_1.png?alt=media&#x26;token=95072107-1cd5-446f-8dc5-6a0500b9e591" alt=""><figcaption></figcaption></figure>

4. The **Binder Name** can be specified in the **Dialogue Trigger** component.

<figure><img src="https://2665493337-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fh8bp6Jx5qkS4c0NEaWR1%2Fuploads%2FnXZnbGa2fjUprwJT40z4%2FScreenshot_2.png?alt=media&#x26;token=00db9f66-09bb-4539-9ee2-815eeeac1ef2" alt=""><figcaption></figcaption></figure>
