Enhance Your Unity2D Dialogue System with Names, Portraits, and Layouts

Enhance Your Unity2D Dialogue System with Names, Portraits, and Layouts

Table of Contents

  1. Introduction
  2. Building the NPC Names and Portraits System
  3. Creating Different Layouts for the Dialog Panel
  4. Using Tags in Ink Dialog Files
  5. Implementing the Display Name in the Dialog Panel
  6. Setting Up the Portraits in Unity
  7. Handling Different Layouts in the Dialog Panel
  8. Resetting Values between NPC Dialogues
  9. Final Thoughts and Conclusion

Introduction

In this article, we will explore a simple yet effective way to display and manage NPC names, portraits, and different layouts for a dialog system built in Unity using ink. By the end of this article, you will have learned how to create a system where NPC names and portraits can easily be changed per line of dialog, and how to change the layout of the dialog panel. We will start by reviewing the basics of the dialog system we built in a previous video, but prior knowledge of that video is not necessary.

Building the NPC Names and Portraits System

To create the NPC names and portraits system, we will use tags in the ink dialog files. These tags are metadata that can be added to any line of dialog and will be read into Unity as strings. We will structure the tags as key-value pairs, where the key represents an action to be performed in C# code and the value represents data to be used for that action. For example, we can use the tag "#speaker:Bob" to set the display name of our dialog panel to "Bob". We will also use tags to set the portraits and layouts of the dialog panel.

Creating Different Layouts for the Dialog Panel

To have different layouts for the dialog panel, we will use animations and an animator controller. We will create a folder for animations and another folder within it for layouts. In the layout folder, we will create an animator controller named "layout animator" and add animations for each layout, such as "Right" and "Left". We will adjust the position of the dialog panel components for each layout and use the animator to switch between them.

Using Tags in Ink Dialog Files

In the ink dialog files, we will add tags to define the speaker, portrait, and layout for each line of dialog. For example, we can use the tags "#speaker:Dr Green" and "#portrait:Dr Green neutral" to set the speaker and portrait for a specific line. We will also use tags to change the speaker and portrait during the dialog, ensuring that the right information is displayed at the right time.

Implementing the Display Name in the Dialog Panel

To display the NPC names in the dialog panel, we will add a TextMeshProUGUI component to the panel and create a reference to it in the dialog manager script. We will handle the display name tags in the script and update the component's text accordingly. This will ensure that the correct name is displayed for each character during the dialog.

Setting Up the Portraits in Unity

To set up the portraits in Unity, we will create an animator controller for the portraits and animations for each different portrait. We will attach the animator controller to the portrait image object and use the "portrait animator.Play()" method in the dialog manager script to play the appropriate animation based on the portrait tag in the ink dialog files.

Handling Different Layouts in the Dialog Panel

To handle different layouts in the dialog panel, we will create an animator controller for the layouts and animations for each layout. We will attach the animator controller to the dialog panel and use the "layout animator.Play()" method in the dialog manager script to play the appropriate animation based on the layout tag in the ink dialog files. This will allow us to switch between layouts dynamically.

Resetting Values between NPC Dialogues

To ensure that tag information does not carry over between NPC dialogues, we will reset the animators, display name text, and other relevant values to their default values when a new dialogue starts. This will prevent any unintended display of information from previous conversations and ensure a clean slate for each NPC interaction.

Final Thoughts and Conclusion

In this article, we have learned how to create a system for displaying and managing NPC names, portraits, and different layouts in a dialog system built in Unity using ink. By implementing tags in the ink dialog files and handling them in the dialog manager script, we can easily change the display name, portraits, and layouts for each line of dialog. This system allows for greater flexibility and customization in NPC interactions, enhancing the overall player experience. Experiment with different tags and layouts to create more immersive and engaging dialogues in your Unity projects.

I am an ordinary seo worker. My job is seo writing. After contacting Proseoai, I became a professional seo user. I learned a lot about seo on Proseoai. And mastered the content of seo link building. Now, I am very confident in handling my seo work. Thanks to Proseoai, I would recommend it to everyone I know. — Jean

Browse More Content