コード例 #1
0
ファイル: DialogueGraph.cs プロジェクト: Eyas/DialogueSystem
        public void AddChoicePort(ChoiceNode node, string questionValue, string next = "")
        {
            var port       = CreatePort(Direction.Output);
            int questIndex = node.choiceCount;

            port.portName = $"Choice {node.choiceCount}";


            var lineText = new TextField
            {
                name      = string.Empty,
                multiline = true
            };

            lineText.value = questionValue;
            (port as DialoguePort).Question = questionValue;
            lineText.RegisterValueChangedCallback(e => {
                (port as DialoguePort).Question = e.newValue;
            });
            (port as DialoguePort).Next = next;
            node.choiceCount++;
            node.outputContainer.Add(port);
            node.outputContainer.Add(lineText);

            node.RefreshPorts();
            node.RefreshExpandedState();
        }
コード例 #2
0
 public override void BuildContextualMenu(ContextualMenuPopulateEvent evt)
 {
     if (evt.target is GraphView)
     {
         evt.menu.AppendAction("Create Dialogue Node", delegate(DropdownMenuAction a)
         {
             var node    = DialogueNode.Create("Dialogue Node", new DialogueProperties());
             var nodePos = this.contentViewContainer.WorldToLocal(a.eventInfo.mousePosition);
             node.SetPosition(new Rect(nodePos, nodeSize));
             AddElement(node);
         });
     }
     if (evt.target is GraphView)
     {
         evt.menu.AppendAction("Create Choice Node", delegate(DropdownMenuAction a)
         {
             var node    = ChoiceNode.Create("Choice Node");
             var nodePos = this.contentViewContainer.WorldToLocal(a.eventInfo.mousePosition);
             node.SetPosition(new Rect(nodePos, nodeSize));
             AddElement(node);
         });
     }
     if (evt.target is BlackboardSection)
     {
         evt.menu.AppendAction("Create", null);
     }
     base.BuildContextualMenu(evt);
 }
コード例 #3
0
 private void GenerateNodeFromContainer(DialogueData dialogueContainer)
 {
     foreach (var node in dialogueContainer.Nodes)
     {
         if (node.isEntryPoint)
         {
             var entryPoint = Nodes.Find(n => n.isEntryPoint);
             entryPoint.Guid = node.Guid;
             (entryPoint.outputContainer.Q <Port>() as DialoguePort).Next = node.Next;
             continue;
         }
         if (node.isChoiceNode)
         {
             ChoiceNode temp = graph.CreateChoiceNode("Choice Node");
             temp.Guid = node.Guid;
             foreach (var choice in node.Choices)
             {
                 graph.AddChoicePort(temp as ChoiceNode, choice.Question, choice.Next);
             }
             temp.SetPosition(new Rect(JsonUtility.FromJson <Vector2>(node.JsonData), graph.nodeSize));
             graph.AddElement(temp);
         }
         else
         {
             DialogueNode temp = graph.CreateDialogueNode("Dialogue Node", node.Text, node.Character, node.Next);;
             temp.Guid = node.Guid;
             temp.SetPosition(new Rect(JsonUtility.FromJson <Vector2>(node.JsonData), graph.nodeSize));
             graph.AddElement(temp);
         }
     }
 }
コード例 #4
0
        private void CreateGraph()
        {
            graph = new DialogueGraph()
            {
                name = "Dialogue Graph"
            };
            graph.StretchToParentSize();
            rootVisualElement.Add(graph);

            var toolbar = new Toolbar();


            var addDilogueNodeButton = new Button(() =>
            {
                graph.AddElement(DialogueNode.Create("Dialogue Node", new DialogueProperties()));
            })
            {
                text = "New Dialogue Node"
            };

            var createChoiceNodeButton = new Button(() =>
            {
                graph.AddElement(ChoiceNode.Create("Choice Node"));
            })
            {
                text = "New Choice Node"
            };

            var saveButton = new Button(() =>
            {
                var saveUtility = DataUtilities.GetInstance(graph, container);
                saveUtility.SaveGraph(path);
            })
            {
                text = "Save"
            };

            toolbar.Add(addDilogueNodeButton);
            toolbar.Add(createChoiceNodeButton);
            toolbar.Add(saveButton);



            rootVisualElement.Add(toolbar);
        }
コード例 #5
0
 private void GenerateNodeFromContainer(DialogueData dialogueContainer)
 {
     foreach (var node in dialogueContainer.Nodes)
     {
         if (node.isEntryPoint)
         {
             var entryPoint = Nodes.Find(n => n.isEntryPoint);
             entryPoint.Guid = node.Guid;
             (entryPoint.outputContainer.Q <Port>() as DialoguePort).Next = node.Next;
             continue;
         }
         if (node.isChoiceNode)
         {
             ChoiceNode temp = ChoiceNode.Create("Choice Node");
             temp.Guid = node.Guid;
             foreach (var choice in node.Choices)
             {
                 ChoiceNode.AddChoicePort(temp, choice.Question, choice.Next);
             }
             temp.SetPosition(new Rect(JsonUtility.FromJson <Vector2>(node.JsonData), graph.nodeSize));
             graph.AddElement(temp);
         }
         else
         {
             var properties = new DialogueProperties
             {
                 Text                = node.Properties.Text,
                 Speaker             = node.Properties.Speaker,
                 speakerPosition     = node.Properties.speakerPosition,
                 Conversant1         = node.Properties.Conversant1,
                 conversant1Position = node.Properties.conversant1Position,
                 Conversant2         = node.Properties.Conversant2,
                 conversant2Position = node.Properties.conversant2Position
             };
             DialogueNode temp = DialogueNode.Create("Dialogue Node", properties, node.Next);
             temp.Guid = node.Guid;
             temp.SetPosition(new Rect(JsonUtility.FromJson <Vector2>(node.JsonData), graph.nodeSize));
             graph.AddElement(temp);
         }
     }
 }
コード例 #6
0
ファイル: ChoiceNode.cs プロジェクト: Suyatna/DialogueSystem
        public static ChoiceNode Create(string title)
        {
            var node = new ChoiceNode
            {
                title        = title,
                Guid         = System.Guid.NewGuid().ToString(),
                isChoiceNode = true,
                name         = "CustomNode",
            };

            var inputPort = DialoguePort.Create(Direction.Input, Port.Capacity.Multi);

            inputPort.portName = "Prev";

            node.inputContainer.Add(inputPort);

            var choiceButton = new Button(() => {
                AddChoicePort(node, string.Empty);
            });

            choiceButton.text = "Add Branch";
            node.titleButtonContainer.Add(choiceButton);



            ///Begin Log Button, if its Delete Later
            var LogButton = new Button(() =>
            {
                //node.Questions.ForEach(e => Debug.Log($"<color=red>{e}</color>"));
            })
            {
                text = "Log Data"
            };

            node.titleButtonContainer.Add(LogButton);
            ///End Log Button


            return(node);
        }