Ejemplo n.º 1
0
 public int GetOutputIndex(OutputNode p_node)
 {
     return(Nodes.FindAll(n => n is OutputNode).IndexOf(p_node));
 }
Ejemplo n.º 2
0
 void IInternalGraphAccess.OutputExecuted(OutputNode p_node, NodeFlowData p_flowData)
 {
     OnOutput?.Invoke(p_node, p_flowData);
 }
Ejemplo n.º 3
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);
        }