Esempio n. 1
0
        public static void UnpackNodesFromSubGraph(DashGraph p_graph, SubGraphNode p_subGraphNode)
        {
            List <NodeConnection> oldInputConnections =
                p_graph.Connections.FindAll(c => c.inputNode == p_subGraphNode);
            List <NodeConnection> oldOutputConnections =
                p_graph.Connections.FindAll(c => c.outputNode == p_subGraphNode);

            List <NodeBase> newNodes    = DuplicateNodes(p_graph, p_subGraphNode.SubGraph.Nodes);
            List <NodeBase> inputNodes  = newNodes.FindAll(n => n is InputNode);
            List <NodeBase> outputNodes = newNodes.FindAll(n => n is OutputNode);

            foreach (var connection in oldInputConnections)
            {
                var oldConnection = p_graph.Connections.Find(c => c.outputNode == inputNodes[connection.inputIndex]);
                p_graph.Connect(oldConnection.inputNode, oldConnection.inputIndex, connection.outputNode,
                                connection.outputIndex);
            }

            foreach (var connection in oldOutputConnections)
            {
                var oldConnection = p_graph.Connections.Find(c => c.inputNode == outputNodes[connection.outputIndex]);
                p_graph.Connect(connection.inputNode, connection.inputIndex, oldConnection.outputNode,
                                oldConnection.outputIndex);
            }

            inputNodes.ForEach(n => p_graph.DeleteNode(n));
            outputNodes.ForEach(n => p_graph.DeleteNode(n));
            p_graph.DeleteNode(p_subGraphNode);
        }
Esempio n. 2
0
        public static void UnpackSelectedSubGraphNode(DashGraph p_graph, SubGraphNode p_subGraphNode)
        {
            if (p_graph == null || p_subGraphNode == null)
            {
                return;
            }

            UndoUtils.RegisterCompleteObject(p_graph, "Unpack SubGraph");
            selectedNodes.Clear();

            NodeUtils.UnpackNodesFromSubGraph(p_graph, p_subGraphNode);

            DashEditorCore.SetDirty();
        }
Esempio n. 3
0
        public static void CreateSubGraphFromSelectedNodes(DashGraph p_graph)
        {
            if (p_graph == null || selectedNodes.Count == 0)
            {
                return;
            }

            UndoUtils.RegisterCompleteObject(p_graph, "Create SubGraph");

            List <NodeBase> nodes        = selectedNodes.Select(i => p_graph.Nodes[i]).ToList();
            SubGraphNode    subGraphNode = NodeUtils.PackNodesToSubGraph(p_graph, nodes);

            selectedNodes.Clear();
            selectedNodes.Add(subGraphNode.Index);

            DashEditorCore.SetDirty();
        }
Esempio n. 4
0
        public static DashGraph GetGraphAtPath(DashGraph p_graph, string p_path)
        {
            if (string.IsNullOrWhiteSpace(p_path))
            {
                return(p_graph);
            }

            List <string> split        = p_path.Split('/').ToList();
            DashGraph     currentGraph = p_graph;

            foreach (string id in split)
            {
                SubGraphNode node = currentGraph.GetNodeById(id) as SubGraphNode;
                if (node == null)
                {
                    Debug.LogWarning("Cannot retrieve subgraph at invalid graph path " + p_path);
                    return(null);
                }

                currentGraph = node.GetSubGraphInstance();
            }

            return(currentGraph);
        }
Esempio n. 5
0
        public static SubGraphNode PackNodesToSubGraph(DashGraph p_graph, List <NodeBase> p_nodes)
        {
            Vector2 center = Vector2.zero;

            p_nodes.ForEach(n => center += n.rect.center);
            center /= p_nodes.Count;

            SubGraphNode    subGraphNode = (SubGraphNode)CreateNode(p_graph, typeof(SubGraphNode), center);
            List <NodeBase> newNodes     = DuplicateNodes(subGraphNode.SubGraph, p_nodes);

            List <NodeConnection> inputs  = new List <NodeConnection>();
            List <NodeConnection> outputs = new List <NodeConnection>();

            p_nodes.ForEach(node =>
            {
                // Check for inputs
                inputs = inputs.Concat(p_graph.Connections.FindAll(c =>
                {
                    bool valid = c.inputNode == node;
                    p_nodes.ForEach(n => valid = valid && n != c.outputNode);
                    return(valid);
                })).ToList();

                outputs = outputs.Concat(p_graph.Connections.FindAll(c =>
                {
                    bool valid = c.outputNode == node;
                    p_nodes.ForEach(n => valid = valid && n != c.inputNode);
                    return(valid);
                })).ToList();
            });

            NodeBase previousNode = null;
            int      index        = 0;

            foreach (var connection in inputs)
            {
                if (previousNode != connection.inputNode)
                {
                    InputNode inputNode = (InputNode)CreateNode(subGraphNode.SubGraph, typeof(InputNode),
                                                                connection.inputNode.rect.position - new Vector2(200, index * 100));
                    subGraphNode.SubGraph.Connect(newNodes[p_nodes.IndexOf(connection.inputNode)],
                                                  connection.inputIndex, inputNode, 0);
                    p_graph.Connect(subGraphNode, index++, connection.outputNode, connection.outputIndex);
                    previousNode = connection.inputNode;
                }
                else
                {
                    p_graph.Connect(subGraphNode, index - 1, connection.outputNode, connection.outputIndex);
                }
            }

            previousNode = null;
            index        = 0;
            foreach (var connection in outputs)
            {
                if (previousNode != connection.outputNode)
                {
                    OutputNode outputNode = (OutputNode)CreateNode(subGraphNode.SubGraph, typeof(OutputNode),
                                                                   connection.outputNode.rect.position + new Vector2(300, index * 100));
                    subGraphNode.SubGraph.Connect(outputNode, 0, newNodes[p_nodes.IndexOf(connection.outputNode)],
                                                  connection.outputIndex);
                    p_graph.Connect(connection.inputNode, connection.inputIndex, subGraphNode, index++);
                    previousNode = connection.outputNode;
                }
                else
                {
                    p_graph.Connect(connection.inputNode, connection.inputIndex, subGraphNode, index - 1);
                }
            }

            p_nodes.ForEach(n => p_graph.DeleteNode(n));

            return(subGraphNode);
        }