Behind the Code
Documentation
Documentation
This system was the most difficult to implement and is integral to converting the graph nodes to conversations in the game. I use scriptable objects to store all of the information in a conversation tree, and many scripts reference each other to make it function properly. The data below can be found in any Conversation Tree asset in the inspector. Two important factors that every single node stores is:
Node GUID: a unique identity that is specific to this current node.
Target Node GUID: the ID of the node that is connected to this node and comes after.
Pos: The position of the node on the graph editor
The DS_DialogueEditorWindow.cs script contains a toolbar with a save and load button. When the user clicks either button, a callback event is sent to either the Save() or Load() methods where we pass over the current conversation tree to another script that will handle all of our logic (DS_SaveAndLoad).
In this Save and Load script, we essentially create a list of all the edges and nodes found in the graph view so we can reference them when saving. As mentioned previously, each node contains a GUID of itself and the node it's connected to, so when we save or load a graph, we loop through the amount of each node type in the graph and store or retrieve all its information into or from the Conversation Tree Scriptable Object. Below is a screenshot of all the data specific to a dialogue node that we must save.
Interact Points are used to hold the Conversation Trees we create and initiate the dialogue if the player reacts to the button prompts. Below is a diagram of how the interact points are currently structured in the project. The "InteractableObject_InteractPointConversation.cs" script can be found on the "Interact Point" prefab.
With Unity's Editor tools, it's surprisingly easy to create a blank editor window.
You must first make a public static bool method with the 2 parameters shown in the screenshot provided. Above the method you also must write the [OnOpenAsset(1)] Attribute which allows this method to execute when we open any Unity Asset. the "1" in [OnOpenAsset(1)] refers to the order of execution starting at index 0. It's useful if you have multiple [OnOpenAsset()] attributes called.
The first line gets the object that we are trying to open, then, if the item we're trying to open is a conversation tree scriptable object, we create a new window by calling the "GetWindow()" method! We assign the editor window a title and minimum size, then load in it's information.
Unity's Style Sheets (uss) is used to modify the properties of each graph node. To begin styling a node, we first have to assign the nodes a Class. For more information on HTML, CSS, and classes, you can refer to this link here: https://www.w3schools.com/html/html_classes.asp
In each of the node's constructor classes, I add a class to that node. You can use Unity's AddToClass("className") to add a class to the current visual element. Now each node has an identity we can refer to when writing our uss properties. To modify a class, first, create a .uss script and then write .className{} for example, if my dialogue node has a class "dialogueNode" attached to it, I can call .dialogueNode{background-color: rgb(0,0,0); } to assign the background black.
To actually see the results however, we must go to our base node script and add the style sheet to this UI element. Unity contains a method styleSheets.Add(), so all we have to do is find it in our resources folder and load it in.