Ejemplo n.º 1
0
        private void AddNode(Vector2 pos)
        {
            DialogueNode node = new DialogueNode(GenerateNodeID(), pos, nodeWidth, nodeHeigth, NodeConnectionPointClicked, RemoveNode, NodeActorIDChanged);

            nodes.Add(node);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Method responsible for saving the Dialogue
        /// </summary>
        /// <param name="view">GraphView component that contains the
        /// Dialogue Nodes</param>
        /// <param name="dialogueName">Name of the passed Dialogue</param>
        public void SaveDialogues(GraphView view, string dialogueName)
        {
            if (dialogueName == null)
            {
                dialogueName = "InitialName";
            }

            //https://answers.unity.com/questions/437391/prompting-dialogue-box-for-input-in-editor.html
            string path =
                EditorUtility.SaveFilePanelInProject("Save Your Dialogue",
                                                     dialogueName + ".asset", "asset",
                                                     "Please select file name to save dialogue to:",
                                                     "Assets/DialogueSystem/Dialogues");

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            DialogueScript temp =
                ScriptableObject.CreateInstance <DialogueScript>();

            List <Node> nodes =
                view.nodes.ToList().OrderBy(node =>
                                            (node as DialogueNode).GetPosition().x).ToList <Node>();


            foreach (Node n in nodes)
            {
                DialogueNode nd = n as DialogueNode;

                bool isConnected = false;
                bool isStart     = false;

                //Check if they have any imput connections
                foreach (Port p in n.inputContainer.Children())
                {
                    if (p.connected)
                    {
                        isConnected = true;

                        //Check if the connection is the start
                        foreach (Edge e in p.connections)
                        {
                            DialogueNode outNode =
                                e.output.node as DialogueNode;

                            if (outNode.title == "Start")
                            {
                                isStart = true;
                            }
                        }
                    }
                }

                if (!isConnected)
                {
                    continue;
                }

                List <OutportData> outPort = new List <OutportData>();

                //Create list of Outport IDs
                foreach (UnityEngine.UIElements.VisualElement welp
                         in n.outputContainer.Children())
                {
                    if (!(welp is Port))
                    {
                        continue;
                    }

                    Port p = welp as Port;

                    if (p.connected)
                    {
                        foreach (Edge e in p.connections)
                        {
                            DialogueNode outNode
                                = e.input.node as DialogueNode;
                            outPort.Add(
                                new OutportData(p.portName, outNode.GUID));
                        }
                    }
                }

                NodeData data = new NodeData(
                    start: isStart,
                    pos: nd.GetPosition(),
                    guID: nd.GUID,
                    dialogue: nd.DialogText,
                    outPorts: outPort
                    );

                temp.FillDialogueDic(data);
            }

            string[] dir = path.Split('/');

            temp.DialogueName = dir[dir.Length - 1].Replace(".asset", "");


            AssetDatabase.CreateAsset(temp, path);
            AssetDatabase.SaveAssets();
        }