Welcome to the **Dialogue System** **for Unity,** a flexible tool for creating interactive conversations in your games! This system supports building dialogues via GameObject hierarchies or JSON files, with export/import functionality and a visual editor for GameObject-based setups. Below, you’ll find an overview of the scripts, setup instructions, and step-by-step guides for creating conversations.
### **Overview**
The Dialogue System consists of four core scripts and an optional editor tool, designed to work together to display character dialogues with sprites, audio, animations, and environmental effects. It’s built for Unity and uses a prefab-based approach for easy integration.
### **Prefabs in the .unitypackage**
1. **Canvas-DialogueDisplay**
- Canvas with **DialoguePanel** and **CharacterPanel** as children.
- Contains UI elements: **TMP_Text** for dialogue and names, **Image** for sprites, and a three **Button[]s** for choices. These are arranged by a **VerticalLayoutGroup** on the **DialoguePanel**.
2. **DialogueManager**
- GameObject with **DialogueManager** script and an **AudioSource**.
- Child: **TypingAudioSource** with its own **AudioSource**.
3. **Merchant-NPC**
- NPC node with **NPCConversationManager** and **AudioSource**.
- Child: **DialogueRoot** with **Environment** and nested **DialogueAuthoringNode** children.
---
### **Unity Editor Setup**
Here’s how to set up the Dialogue System in the Unity Editor using the provided prefabs.
#### **Initial Setup**
1. Import the **.unitypackage**:
- In Unity, go to **Assets > Import Package > Custom Package**, select the **.unitypackage**, and import all assets.
2. **Scene Hierarchy**:
```text
- Canvas-DialogueDisplay (Prefab Instance)
- DialoguePanel
- DialogueText (TMP_Text)
- Choice1 (Button[])
- Text (TMP_Text)
- Choice2 (Button[])
- Text (TMP_Text)
- Choice3 (Button[])
- Text (TMP_Text)
- CharacterPanel
- CharacterSpriteImage (Image)
- CharacterNameText (TMP_Text)
- EmotionalStateText (TMP_Text)
- PlayerPanel
- PlayerSpriteImage (Image)
- PlayerNameText (TMP_Text)
- PlayerEmotionalStateText (TMP_Text)
- InteractionPrompt-Text (TMP_Text)
- EventSystem
- DialogueManager (Prefab Instance)
- TypingAudioSource (Child with AudioSource)
- Merchant-NPC (Prefab Instance)
- DialogueRoot
- Start [DialogueAuthoringNode]
- Node2 [DialogueAuthoringNode]
- Node3 [DialogueAuthoringNode]
```
- Drag the prefabs into your scene to create this structure.
3. **Configure DialogueManager:**
- Select **DialogueManager** in the Hierarchy.
- In the Inspector, assign:
- **Dialogue Text**: **DialoguePanel/DialogueText**.
- **Character Name Text**: **CharacterPanel/CharacterNameText**.
- **Character Sprite Image**: **CharacterPanel/CharacterSpriteImage**.
- **Environment Image**: An **Image** component on **Canvas-DialogueDisplay** (add if missing).
- **Emotional State Text**: **CharacterPanel/EmotionalStateText**.
- **Choice Buttons**: Drag the **Button[]** array from **DialoguePanel**.
- **Dialogue Panel**: **DialoguePanel** GameObject.
- **Character Panel**: **CharacterPanel** GameObject.
- **Character Animation**: An **Animation** component (add to **CharacterSpriteImage** if needed).
- **Typing Sound**: An **AudioClip** for typing effects.
- Ensure **TypingAudioSource** child has an **AudioSource**.
4. **Configure Merchant-NPC:**
- Select **Merchant-NPC**.
- Ensure it has an **AudioSource** (auto-added by **[RequireComponent]**).
- Expand **Conversations** array in **NPCConversationManager**—leave empty for now.
### **Scripts**
See **[[6. Scripts Overview]]** for a breakdown of what each script does.