示例#1
0
    private static void SaveNodes(DialogueGraphView graphView, GraphItem graphItem)
    {
        graphItem.NodeLinks.Clear();
        var connectedSockets = graphView.edges.ToList().Where(x => x.input.node != null).ToArray();

        for (var i = 0; i < connectedSockets.Count(); i++)
        {
            var outputNode = (connectedSockets[i].output.node as BaseNode);
            var inputNode  = (connectedSockets[i].input.node as BaseNode);
            graphItem.NodeLinks.Add(new NodeLinkData
            {
                baseNodeGuid   = outputNode.nodeGuid,
                outputPortName = connectedSockets[i].output.portName,
                inputPortName  = connectedSockets[i].input.portName,
                targetNodeGuid = inputNode.nodeGuid,
            });
        }

        graphItem.NodeData.Clear();
        foreach (var node in graphView.nodes.ToList().Cast <BaseNode>())
        {
            graphItem.NodeData.Add(new NodeData
            {
                nodeGuid           = node.nodeGuid,
                position           = node.GetPosition().position,
                nodeType           = node.GetType().FullName,
                additionalDataJSON = node.CreateAdditionalData()
            });
        }
    }
示例#2
0
    public static void ClearGraph(DialogueGraphView graph)
    {
        var Nodes = graph.nodes.ToList().Cast <DialogueNode>().ToList();
        //将起始节点 guid 设置为 缓存中的起始节点
        //Nodes.Find(x => x.EntryPoint).GUID = _containerCache.NodeLinks[0].BaseNodeGuid;
        var edges = graph.edges.ToList();

        foreach (var node in Nodes)
        {
            //保留起始点
            if (node.EntryPoint)
            {
                continue;
            }
            //找到所有链接当前节点的边,删除该边
            edges.Where(x => x.input.node == node)
            .ToList()
            .ForEach(edge => graph.RemoveElement(edge));

            //删除完边后,删除节点
            graph.RemoveElement(node);
        }

        var entryNode = Nodes.Find(x => x.EntryPoint);

        using (var outputs = entryNode.outputContainer.Children().GetEnumerator()) {
            while (outputs.MoveNext())
            {
                var port = outputs.Current.Q <Port>();
                port.DisconnectAll();
            }
            entryNode.RefreshExpandedState();
            entryNode.RefreshPorts();
        }
    }
 public static GraphContextMenuUtility GetInstance(DialogueGraphView graphView)
 {
     return(new GraphContextMenuUtility
     {
         targetGraphView = graphView
     });
 }
示例#4
0
 public static void Save(DialogueGraphView graphView, GraphItem graphItem)
 {
     SaveNodes(graphView, graphItem);
     EditorUtility.SetDirty(graphItem);
     AssetDatabase.SaveAssets();
     AssetDatabase.Refresh();
 }
 public static GraphSaveUtility GetInstance(DialogueGraphView targetGraphView)
 {
     return(new GraphSaveUtility
     {
         _targetGraphView = targetGraphView,
     });
 }
示例#6
0
    private static void ConnectNodes(DialogueGraphView graphView, DialogueContainer dialogueContainer)
    {
        var nodes = graphView.nodes.ToList().Cast <DialogueNode>().ToList();

        for (int i = 0; i < nodes.Count; i++)
        {
            var cuNode = nodes[i];

            //找到所有从此节点开始的连线
            var connections = dialogueContainer.NodeLinks
                              .Where(x => x.FromNodeGuid == cuNode.GUID)
                              .ToList();

            for (int j = 0; j < connections.Count; j++)
            {
                var targetNodeGuid = connections[j].ToNodeGuid;
                //找到这条连线的目标节点
                var targetNode = nodes.First(x => x.GUID == targetNodeGuid);

                LinkNodes(graphView,
                          cuNode.outputContainer[j].Q <Port>(),
                          (Port)targetNode.inputContainer[0]);
                //获取端口的两种表示方法
            }
        }
    }
示例#7
0
 private static void ClearGraph(DialogueGraphView graphView)
 {
     foreach (var perNode in graphView.nodes.ToList())
     {
         graphView.edges.ToList().Where(x => x.input.node == perNode).ToList().ForEach(edge => graphView.RemoveElement(edge));
         graphView.RemoveElement(perNode);
     }
 }
    public void Init(EditorWindow window, DialogueGraphView graphView)
    {
        this.window    = window;
        this.graphView = graphView;

        indentationIcon = new Texture2D(1, 1);
        indentationIcon.SetPixel(0, 0, new Color(0, 0, 0, 0));
        indentationIcon.Apply();
    }
示例#9
0
 public void Init(EditorWindow window, DialogueGraphView graphView)
 {
     _graphView = graphView;
     _window    = window;
     //Indentation hack for search window as a transparent icon
     _indeantationIcon = new Texture2D(1, 1);
     _indeantationIcon.SetPixel(0, 0, new Color(0, 0, 0, 0)); //Dont forget to set the alpha to 0 as well
     _indeantationIcon.Apply();
 }
示例#10
0
 private void ConstructGraphView()
 {
     graphView = new DialogueGraphView(this)
     {
         name = "Diualogue Graph",
     };
     graphView.StretchToParentSize();
     rootVisualElement.Add(graphView);
 }
    public void Init(DialogueGraph _editorWindow, DialogueGraphView _graphView)
    {
        window    = _editorWindow;
        graphView = _graphView;

        pic = new Texture2D(1, 1);
        pic.SetPixel(0, 0, new Color(0, 0, 0, 0));
        pic.Apply();
    }
    public void Init(DialogueGraphView graphView, EditorWindow window)
    {
        _graphView = graphView;
        _window    = window;

        _indentationIcon = new Texture2D(1, 1);
        _indentationIcon.SetPixel(0, 0, new Color(0, 0, 0, 0));
        _indentationIcon.Apply();
    }
    public void Configure(DialogueEditorWindow _editorWindow, DialogueGraphView _graphView)
    {
        editorWindow = _editorWindow;
        graphView    = _graphView;

        pic = new Texture2D(1, 1);
        pic.SetPixel(0, 0, new Color(0, 0, 0, 0));
        pic.Apply();
    }
    private void ConstructGraphView()
    {
        _graphView = new DialogueGraphView
        {
            name = "Dialogue Graph"
        };

        rootVisualElement.Add(_graphView);
    }
示例#15
0
    private void ConstructGraphView()
    {
        _graphView = new DialogueGraphView {
            name = "Dialogue Graph"
        };

        _graphView.StretchToParentSize();
        rootVisualElement.Add(_graphView);
    }
    public void Init(EditorWindow window, DialogueGraphView view)
    {
        _graphView    = view;
        _editorWindow = window;

        // Indentation Hack for search window SearchTreeEntry as a transparent icon
        _indentationIcon = new Texture2D(1, 1);
        _indentationIcon.SetPixel(0, 0, new Color(0, 0, 0, 0));
        _indentationIcon.Apply();
    }
示例#17
0
    void Construct()
    {
        graphView = new DialogueGraphView
        {
            name = "Dialogue Graph"
        };

        graphView.StretchToParentSize();
        rootVisualElement.Add(graphView);

        graphView.SendToBack();
    }
示例#18
0
    private static void LinkNodes(DialogueGraphView graphView, Port output, Port input)
    {
        var tempEdge = new Edge
        {
            output = output,
            input  = input
        };

        tempEdge.input.Connect(tempEdge);
        tempEdge.output.Connect(tempEdge);

        graphView.Add(tempEdge);
    }
示例#19
0
    public StartNode(Vector2 _position, DialogueEditorWindow _editorWindow, DialogueGraphView _graphView)
    {
        editorWindow = _editorWindow;
        graphView    = _graphView;

        title = "Start";
        SetPosition(new Rect(_position, defaultNodeSize));
        NodeGuid = Guid.NewGuid().ToString();

        AddOutputPort("Output", Port.Capacity.Single);

        RefreshExpandedState();
        RefreshPorts();
    }
示例#20
0
    public static void LoadGraph(string fileName, DialogueGraphView graphView)
    {
        var graphDataCache = Resources.Load <DialogueContainer>(fileName);

        if (graphDataCache == null)
        {
            EditorUtility.DisplayDialog("找不到文件", "目标 dialogue graph 不存在", "确定");
            return;
        }

        ClearGraph(graphView);
        CreateNodes(graphView, graphDataCache);
        ConnectNodes(graphView, graphDataCache);
    }
    public DialogueNode(Vector3 _position, DialogueGraphView _graphView)
    {
        graphView = _graphView;

        Initialize("Dialogue Node", Guid.NewGuid().ToString());
        SetupPorts();

        SetupCharacterSelection(0);

        RefreshExpandedState();
        RefreshPorts();
        SetPosition(new Rect(_position, defaultNodeSize));

        AddTextField();
    }
示例#22
0
    private static void CreateNodes(DialogueGraphView graphView, DialogueContainer dialogueContainer)
    {
        foreach (var nodeData in dialogueContainer.DialogueNodeData)
        {
            var tempNode = graphView.CreateDialogueNode(nodeData.DialogueText, nodeData.Position);
            tempNode.Load(nodeData);
            graphView.AddElement(tempNode);

            //添加端口
            var nodePorts = dialogueContainer.NodeLinks.Where(x => x.FromNodeGuid == nodeData.Guid).ToList();
            nodePorts.ForEach(x => graphView.AddChoicePort(tempNode, x.PortName));
        }

        graphView.EntryNode.Load(dialogueContainer.EntryNodeData, true);
    }
    public ChoiceNode(Vector3 _position, DialogueGraphView _graphView)
    {
        graphView = _graphView;
        
        Initialize();
        SetupInputPort();
        
        // Generate dropdown for Character
        SetupCharacterSelection(0);

        RefreshExpandedState();
        RefreshPorts();
        SetPosition(new Rect(_position, defaultNodeSize));

        AddChoicePort();
    }
示例#24
0
    private static void ConnectDialogueNodes(DialogueGraphView graphView, GraphItem graphItem)
    {
        var nodes = graphView.nodes.ToList().Cast <BaseNode>();

        foreach (var edge in graphItem.NodeLinks)
        {
            var baseNode   = nodes.SingleOrDefault(x => x.nodeGuid == edge.baseNodeGuid);
            var targetNode = nodes.SingleOrDefault(x => x.nodeGuid == edge.targetNodeGuid);

            var baseNodePort   = baseNode.GetOutputPort(edge.outputPortName);
            var targetNodePort = targetNode.GetInputPort(edge.inputPortName);

            var createdEdge = LinkNodesTogether(baseNodePort, targetNodePort);
            graphView.Add(createdEdge);
        }
    }
    public CharacterProperty(string propertyName, string propertyValue, DialogueGraphView dialogueGraphView)
    {
        graphView     = dialogueGraphView;
        propertyType  = BlackboardType.Character;
        PropertyName  = propertyName;
        PropertyValue = propertyValue;

        propertyElement = new VisualElement();
        var blackboardField = new BlackboardField {
            text = propertyName, typeText = "Character"
        };

        blackboardField.Q <Label>("typeLabel").style.flexBasis = StyleKeyword.Auto;
        blackboardField.capabilities &= ~Capabilities.Deletable;

        blackboardField.RegisterCallback <ContextualMenuPopulateEvent>(PopulateDeleteOption);
        blackboardField.Add(new Button(() => { graphView.RemovePropertyFromBlackboard(this.PropertyName); })
        {
            text = "X"
        });

        propertyElement.Add(blackboardField);

        var propertyValueTextField = new TextField("Value:")
        {
            value = PropertyValue
        };

        propertyValueTextField.Q <Label>().style.minWidth = StyleKeyword.Auto;

        propertyValueTextField.RegisterValueChangedCallback(evt =>
        {
            var changingPropertyIndex = graphView.exposedProperties.FindIndex(x => x.PropertyName == this.PropertyName);

            if (changingPropertyIndex < 0)
            {
                return;
            }

            graphView.exposedProperties[changingPropertyIndex].PropertyValue = evt.newValue;
            propertyValueTextField.value = evt.newValue;
        });

        var blackboardValueRow = new BlackboardRow(blackboardField, propertyValueTextField);

        propertyElement.Add(blackboardValueRow);
    }
示例#26
0
    public static void SaveGraph(string _fileName, DialogueGraphView targetGraphView)
    {
        var edges = targetGraphView.edges.ToList();

        if (!edges.Any())
        {
            return;
        }

        var dialogueContainer = ScriptableObject.CreateInstance <DialogueContainer>();
        var connectedPorts    = edges.Where(x => x.input.node != null).ToArray();

        for (int i = 0; i < connectedPorts.Length; i++)
        {
            var outputNode = connectedPorts[i].output.node as DialogueNode;
            var inputNode  = connectedPorts[i].input.node as DialogueNode;

            dialogueContainer.NodeLinks.Add(new EdgeData {
                FromNodeGuid = outputNode.GUID,
                PortName     = connectedPorts[i].output.portName,
                ToNodeGuid   = inputNode.GUID
            });
        }

        var nodes = targetGraphView.nodes.ToList().Cast <DialogueNode>().ToList();

        foreach (var dialogueNode in nodes.Where(node => !node.EntryPoint))
        {
            if (dialogueNode.EntryPoint)
            {
                dialogueContainer.EntryNodeData = dialogueNode.Save();
            }
            else
            {
                dialogueContainer.DialogueNodeData.Add(dialogueNode.Save());
            }
        }

        if (!AssetDatabase.IsValidFolder("Assets/Resources"))
        {
            AssetDatabase.CreateFolder("Assets", "Resources");
        }

        AssetDatabase.CreateAsset(dialogueContainer, $"Assets/Resources/{_fileName}.asset");
        AssetDatabase.SaveAssets();
    }
示例#27
0
        // Spawning StartNode
        public StartNode(Vector2 position, DialogueEditorWindow newEditorWindow, DialogueGraphView newGraphView)
        {
            // Adding and loading this node .css from /Resources
            StyleSheet styleSheet = Resources.Load <StyleSheet>("NodeStyleSheet");

            styleSheets.Add(styleSheet);

            editorWindow = newEditorWindow;
            graphView    = newGraphView;

            title = "Start";
            SetPosition(new Rect(position, defaultNodeSize));
            nodeGuid = Guid.NewGuid().ToString();

            AddOutputPort("Output", Port.Capacity.Single);

            RefreshExpandedState();
            RefreshPorts();
        }
示例#28
0
    private static void GenerateDialogueNodes(DialogueGraphView graphView, GraphItem graphItem)
    {
        foreach (var node in graphItem.NodeData)
        {
            BaseNode tempNode = null;
            if (node.nodeType == nameof(DialogueNode))
            {
                tempNode = graphView.CreateNode <DialogueNode>("Dialogue", Vector2.zero);
            }
            if (tempNode == null)
            {
                continue;
            }

            tempNode.nodeGuid = node.nodeGuid;
            tempNode.SetPosition(new Rect(node.position, graphView.DefaultNodeSize));
            graphView.AddElement(tempNode);
            tempNode.PopulateAdditionalData(node.additionalDataJSON);
        }
    }
示例#29
0
    public BaseNode(NodeType _nodeType, DialogueGraphView _graphView, Vector2 position = default, string nodeGuid = null)
    {
        graphView = _graphView;

        if (position == default)
        {
            position = defaultPosition;
        }

        switch (_nodeType)
        {
        case NodeType.StartNode:
            SetupStartNode(position, nodeGuid);
            break;

        case NodeType.EndNode:
            SetupEndNode(position, nodeGuid);
            break;
        }
    }
    public ChoiceNode(DialogueGraphView _graphView, BaseNodeData baseData, ChoiceNodeData choiceNodeData, List<NodeLinkData> choicePorts)
    {
        graphView = _graphView;
        
        Initialize(baseData.nodeName, baseData.guid, choiceNodeData.dialogueText);
        SetupInputPort();
        
        // Generate dropdown for Character
        var propertyIndex = _graphView.exposedProperties.FindIndex(x => x.PropertyName == choiceNodeData.speaker);
        SetupCharacterSelection(propertyIndex);

        RefreshExpandedState();
        RefreshPorts();
        SetPosition(new Rect(baseData.position, defaultNodeSize));

        foreach (var port in choicePorts)
        {
            AddChoicePort(port.portName);
        }
    }