Unity Dialogue System - Creating the Single Choice Node

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
We now have our base node in and can position it anywhere we want, so it's time for us to start creating our other two node files. We'll start by creating our single choice node so let's go to our Elements folder and right click in the project Window and create a new C# Script. I'll name it DSSingleChoiceNode. It's important for you to at least have the SingleChoice part of the name, as that's the value we have in our DialogueType Enumeration and we'll be using that to instantiate the node later on. Open it up and remove the default methods and swap the inheritance to DSNode instead. It won't recognize DSNode but that's fine because I'm going to make this script be part of the Elements subnamespace. We won't be adding a lot to this node, in fact, the only thing we'll be adding is a port that mostly looks the same as the input port, but is an output port. To do so we'll be needing to use our DSNode Initialize and Draw methods. But because these methods are specified in the DSNode class with some default code, we need to somehow get them here in a way to call the DSNode base code but also add ours. And to do so we simply go to our DSNode script and make both methods a virtual method. This will allow us to override these methods but also call the base code here, so let's go back to our SingleChoiceNode script and override them. To override them in Visual Studio we enter the class scope and press alt enter and choose the Generate Overrides option. In here we click "Deselect All" and choose the Initialize and Draw methods, pressing "OK" when we're done. The first thing we're going to change here is the type of the dialogue, which we'll be setting to SingleChoice. To do so we need to make sure we import our Enumerations namespace and then type in "DialogueType = DSDialogueType.SingleChoice". Next we'll need to have our choice to add it as an output port. In both nodes we'll be adding the choices to a list and iterate through that list, and for each choice we'll lay it out as a port the way we want. In the SingleChoiceNode case we're only ever going to have one choice, but doing it this way allows us to add more in the future and make the variable reusable through the different node types. So let's add a new choice by typing in "Choices.Add("Next Dialogue")". Now that we have our variables set for this node type let's make our output port and add it to the outputContainer. Let's start by iterating through the choices List by using a foreach so so type in "foreach (string choice in Choices)", and here we'll create a variable of type Port. You will need to import its namespace. I'll name it "choicePort" and Instantiate a port with the same method as in our DSNode class. However, we'll be updating its Direction to be "Output" instead and its Capacity to be "Single". We'll also update its "portName" to have the value of "choice", meaning the choice text will show up as the port text. At the end, add it to the outputContainer. It might be a good idea to call the RefreshExpandedState at the end of each node instead of the base node, just in case we add something that requires it, so let's go back to our DSNode and remove it from there and add it to our SingleChoiceNode. We'll not be showing this node yet as we'll only instantiate it once we finish our MultipleChoiceNode too.
Info
Channel: Indie Wafflus
Views: 434
Rating: undefined out of 5
Keywords: Unity Dialogue System, Unity Dialog System, Unity Graph View, Unity Node, Unity UI Toolkit, Unity Dialogues, Unity Node Based Dialogue System, Dialogue System, Node Based Dialogue System, Unity Dialogs, Unity Visual Elements, Node System, Dialogue System Tutorial, Unity 2D, Unity, Unity Tutorial, Unity Dialogue System Tutorial, Unity 3D, Unity3D, Unity2D
Id: 1RFgaBMffLU
Channel Id: undefined
Length: 4min 20sec (260 seconds)
Published: Sun Jul 25 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.