public DialogueNode CheckState(int state) { Debug.Log("CheckState: Checking: " + state.ToString()); int count = 0; DialogueNode rootNode = null; Debug.Log(dialogueGraph.GetNodeList().Count.ToString()); foreach (DialogueNode node in dialogueGraph.GetNodeList()) { count++; Debug.Log("IF: " + node.GetState().ToString() + " = " + state.ToString()); if (state == node.GetState()) { rootNode = node; Debug.Log(rootNode.GetState().ToString()); break; } } Debug.Log("Went through " + count.ToString() + " to get to root"); if (rootNode == null) { //defaults to first node in list Debug.Log("defaulting"); rootNode = dialogueGraph.GetNodeList()[0]; } return(rootNode); }
public DialogueGraph ConvoGraph() { s.Start (); DialogueGraph convoGraph = new DialogueGraph(); XmlNodeList dialogues = xml.DocumentElement.SelectNodes ("/conversation/dialogue"); /* * Loops through all the dialogue nodes first without * processing any replies, this is because to be able * to link the player questions to corresponding replies * the dialogues need to be accessible in the graph before * they can be linked to. */ foreach (XmlNode dialogueNode in dialogues) { DialogueNode dNode = new DialogueNode(); if(dialogueNode.Attributes["actorname"].Value != null) { dNode.SetActorName(dialogueNode.Attributes["actorname"].Value); } if(dialogueNode.Attributes["actordialogue"].Value !=null) { dNode.SetDialogue(dialogueNode.Attributes["actordialogue"].Value); } if(dialogueNode.Attributes["id"].Value != null) { dNode.SetID (int.Parse (dialogueNode.Attributes["id"].Value)); } if(dialogueNode.Attributes["state"].Value != null) { dNode.SetState(int.Parse(dialogueNode.Attributes["state"].Value)); } convoGraph.AddNode(dNode); } /* * Loops back through the dialogue nodes only * looking at the child node replies */ foreach(XmlNode dialogueNode in dialogues) { foreach (XmlNode childNode in dialogueNode.ChildNodes) { if(childNode.Name.ToUpper().Equals("REPLIES")) { foreach (XmlNode replyNode in childNode.ChildNodes) { DialogueNode repNode = new DialogueNode(); if(replyNode.Attributes["text"].Value != null) { repNode.SetDialogue(replyNode.Attributes["text"].Value); } if(replyNode.Attributes["condition"].Value !=null) { repNode.SetCondition(replyNode.Attributes["condition"].Value); } if(replyNode.Attributes["goto"].Value != null) { if(replyNode.Attributes["goto"].Value.Equals ("-9999")) { //Ends the Conversation UnityEngine.Debug.Log("CONVO OVER"); if(replyNode.Attributes["nextstate"].Value !=null) { repNode.SetNextState(int.Parse (replyNode.Attributes["nextstate"].Value)); } } else { int id = int.Parse(replyNode.Attributes["goto"].Value); convoGraph.AddEdge(repNode, convoGraph.FindNode(id)); } } convoGraph.AddNode (repNode); convoGraph.AddEdge (convoGraph.FindNode(int.Parse(dialogueNode.Attributes["id"].Value)),repNode); UnityEngine.Debug.Log(dialogueNode.Attributes["id"].Value + " to " + repNode.GetDialogue()); } } } } s.Stop(); UnityEngine.Debug.Log("Time Elapsed for " + convoGraph.GetNodeList()[0].GetActorName() + ": " + s.Elapsed + "\nTotal Nodes: " + convoGraph.GetNodeList().Count.ToString()); return convoGraph; }
public DialogueGraph ConvoGraph() { s.Start(); DialogueGraph convoGraph = new DialogueGraph(); XmlNodeList dialogues = xml.DocumentElement.SelectNodes("/conversation/dialogue"); /* * Loops through all the dialogue nodes first without * processing any replies, this is because to be able * to link the player questions to corresponding replies * the dialogues need to be accessible in the graph before * they can be linked to. */ foreach (XmlNode dialogueNode in dialogues) { DialogueNode dNode = new DialogueNode(); if (dialogueNode.Attributes["actorname"].Value != null) { dNode.SetActorName(dialogueNode.Attributes["actorname"].Value); } if (dialogueNode.Attributes["actordialogue"].Value != null) { dNode.SetDialogue(dialogueNode.Attributes["actordialogue"].Value); } if (dialogueNode.Attributes["id"].Value != null) { dNode.SetID(int.Parse(dialogueNode.Attributes["id"].Value)); } if (dialogueNode.Attributes["state"].Value != null) { dNode.SetState(int.Parse(dialogueNode.Attributes["state"].Value)); } convoGraph.AddNode(dNode); } /* * Loops back through the dialogue nodes only * looking at the child node replies */ foreach (XmlNode dialogueNode in dialogues) { foreach (XmlNode childNode in dialogueNode.ChildNodes) { if (childNode.Name.ToUpper().Equals("REPLIES")) { foreach (XmlNode replyNode in childNode.ChildNodes) { DialogueNode repNode = new DialogueNode(); if (replyNode.Attributes["text"].Value != null) { repNode.SetDialogue(replyNode.Attributes["text"].Value); } if (replyNode.Attributes["condition"].Value != null) { repNode.SetCondition(replyNode.Attributes["condition"].Value); } if (replyNode.Attributes["goto"].Value != null) { if (replyNode.Attributes["goto"].Value.Equals("-9999")) { //Ends the Conversation UnityEngine.Debug.Log("CONVO OVER"); if (replyNode.Attributes["nextstate"].Value != null) { repNode.SetNextState(int.Parse(replyNode.Attributes["nextstate"].Value)); } } else { int id = int.Parse(replyNode.Attributes["goto"].Value); convoGraph.AddEdge(repNode, convoGraph.FindNode(id)); } } convoGraph.AddNode(repNode); convoGraph.AddEdge(convoGraph.FindNode(int.Parse(dialogueNode.Attributes["id"].Value)), repNode); UnityEngine.Debug.Log(dialogueNode.Attributes["id"].Value + " to " + repNode.GetDialogue()); } } } } s.Stop(); UnityEngine.Debug.Log("Time Elapsed for " + convoGraph.GetNodeList()[0].GetActorName() + ": " + s.Elapsed + "\nTotal Nodes: " + convoGraph.GetNodeList().Count.ToString()); return(convoGraph); }