This project’s main purpose is to make things, like adding dialogue, more accessible to game designers and other development team members without the need for them to program those features. It is made in Unity Engine using the languages ‘C#’ and ‘XML’
The ‘DialogueEditor’-class is used to create a window in the Unity Editor so the user can create dialogue options using nodes in a ‘node-based’ system. The ‘DialogueSystem’-class acts as a general distributor of the dialogue to the right NPC’s and at the right times and queues.
This project’s main functionality is yet to be implemented: using the editor to generate an ‘XML’-file. This ‘XML’-file will then be deserialized by the ‘DialogueSystem’-class so that the NPC’s are presenting the dialogue and the options as string variables.
This project is, unfortunately, still in development.
private void OnEnable()
{
//Generates a New Style for Node
nodeStyle = new GUIStyle();
nodeStyle.normal.background =
EditorGUIUtility.Load(“builtin skins/darkskin/images/node3.png”) as
Texture2D;
nodeStyle.border = new RectOffset(12, 12, 12, 12);
//Generates a Skin for a Selected Node
selectedStyle = new GUIStyle();
selectedStyle.normal.background =
EditorGUIUtility.Load(“builtin skins/darkskin/images/node3 on.png”) as
Texture2D;
selectedStyle.border = new RectOffset(12, 12, 12, 12);
//Generate Input Display
inPointStyle = new GUIStyle();
inPointStyle.normal.background =
EditorGUIUtility.Load(“builtin skins/darkskin/images/btn left.png”) as
Texture2D;
inPointStyle.active.background =
EditorGUIUtility.Load(“builtin skins/darkskin/images/btn left on.png”)
as Texture2D;
inPointStyle.border = new RectOffset(4, 4, 12, 12);
//Generate Output Display
outPointStyle = new GUIStyle();
outPointStyle.normal.background =
EditorGUIUtility.Load(“builtin skins/darkskin/images/btn right.png”) as
Texture2D;
outPointStyle.active.background =
EditorGUIUtility.Load(“builtin skins/darkskin/images/btn right on.png”)
as Texture2D;
outPointStyle.border = new RectOffset(4, 4, 12, 12);
}
private void AddNode(Vector2 mousePosition)
{
Node aNode = new
Node(mousePosition, 200, 50, nodeStyle, selectedStyle, inPointStyle,
outPointStyle, OnClickInPoint, OnClickOutPoint, RemoveNode);
aNode.Dragging += SetNodeDragging;
nodes.Add(aNode);
}
private void RemoveNode(Node node)
{
//Before the Node Will be Removed, the Connections Need to be Removed First
if (connections != null)
{
//Initialize List of Node Connections to Remove
List<NodeConnection> connectionsToRemove = new List<NodeConnection>();
//Put Node Connections in Said List
for (int i = 0; i < connections.Count; i++)
{
if (connections[i].InPoint == node.InPoint ||
connections[i].OutPoint == node.OutPoint) {
connectionsToRemove.Add(connection[i]);
}
}
//Delete Those Node Connections
for (int i = 0; i < connectionsToRemove.Count; i++) {
connections.Remove(connectionsToRemove[i]);
}
//Clear List of Node Connections to Remove
connectionsToRemove = null;
}
//Remove Node
nodes.Remove(node);
}
void Start()
{
if (_player != null) {
_player.TriggerDialogue += PutInQueue;
}
if (_npcs != null) {
for (int i = 0; i < _npcs.Length; i++) {
_npcs[i].TriggerDialogue += PutInQueue;
}
}
}
void PutInQueue(string npcName, Dialogue[] dialogueSet)
{
StopAllCoroutines();
Activate();
if (dialogueSet.Length > 0) {
StartCoroutine(ActivationCoroutine(1.0f, npcName,
dialogueSet[0].GetSentences()[0], dialogueSet[0].GetOptions()));
}
}
IEnumerator ActivationCoroutine(float seconds, string npcName, string sentence,
string[] options)
{
yield return new WaitForSeconds(seconds);
if (sentence != null) {
ChangeToNext(npcName, sentence);
}
if (options[0] != null) {
Options(options);
}
}