private void NewNode(NodeDataBase data, Vector2 position)
        {
            data.ClearConnectionChildren();
            data.rect.position = position;
            _graph.AddNode(data);
            AssetDatabase.AddObjectToAsset(data, _graph);
            AssetDatabase.SaveAssets();

            var instance = _window.CreateNodeInstance(data);

            _window.Nodes.Add(instance);

            Undo.RegisterCreatedObjectUndo(data, "Create node");
        }
    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);
    }