예제 #1
0
            private static PlaceFitTree BuildTree(UNodeView node, HashSet <UNodeView> flowNodes, HashSet <UNodeView> buildTrees = null, bool includeFlows = true, bool includeInputs = true, bool includeOutputs = true)
            {
                if (buildTrees == null)
                {
                    buildTrees = new HashSet <UNodeView>();
                }
                var result = new PlaceFitTree(node);

                if (includeFlows)                 //Flows
                {
                    var nodes = node.outputPorts.
                                Where((p) => p.connected && p.orientation == Orientation.Vertical && !p.IsProxy()).
                                SelectMany(p => p.GetConnectedNodes()).ToList();
                    foreach (var n in nodes)
                    {
                        if (n == null || buildTrees.Contains(n))
                        {
                            continue;
                        }
                        var childTree = BuildTree(n, flowNodes, buildTrees, includeFlows: true, includeInputs: true, includeOutputs: true);
                        result.flows.Add(childTree);
                    }
                }
                if (includeInputs)                 //Inputs
                {
                    var nodes = node.inputPorts.
                                Where((p) => p.connected && p.orientation == Orientation.Horizontal && !p.IsProxy()).
                                SelectMany(p => p.GetConnectedNodes()).
                                Where(n => !flowNodes.Contains(n)).ToList();
                    foreach (var n in nodes)
                    {
                        if (n == null || buildTrees.Contains(n))
                        {
                            continue;
                        }
                        var childTree = BuildTree(n, flowNodes, buildTrees, includeFlows: includeFlows, includeInputs: includeInputs, false);
                        result.inputs.Add(childTree);
                    }
                }
                if (includeOutputs)                 //Outputs
                {
                    var nodes = node.outputPorts.
                                Where((p) => p.connected && p.orientation == Orientation.Horizontal && !p.IsProxy()).
                                SelectMany(p => p.GetConnectedNodes()).
                                Where(n => !flowNodes.Contains(n)).ToList();
                    foreach (var n in nodes)
                    {
                        if (n == null || buildTrees.Contains(n))
                        {
                            continue;
                        }
                        var childTree = BuildTree(n, flowNodes, buildTrees, includeFlows: includeFlows, includeInputs: false, includeOutputs: includeOutputs);
                        result.outputs.Add(childTree);
                    }
                }
                return(result);
            }
예제 #2
0
            private static List <UNodeView> GetNodes(PlaceFitTree tree, HashSet <UNodeView> oldNodes = null)
            {
                if (oldNodes == null)
                {
                    oldNodes = new HashSet <UNodeView>();
                }
                List <UNodeView> nodes = new List <UNodeView>();

                if (oldNodes.Contains(tree.node))
                {
                    return(nodes);
                }
                nodes.Add(tree.node);
                if (tree.inputs.Count > 0)
                {
                    foreach (var n in tree.inputs)
                    {
                        nodes.AddRange(GetNodes(n, oldNodes));
                    }
                }
                if (tree.outputs.Count > 0)
                {
                    foreach (var n in tree.outputs)
                    {
                        nodes.AddRange(GetNodes(n, oldNodes));
                    }
                }
                if (tree.flows.Count > 0)
                {
                    foreach (var n in tree.flows)
                    {
                        nodes.AddRange(GetNodes(n, oldNodes));
                    }
                }
                return(nodes);
            }
예제 #3
0
            private static void PlaceFitNodes(PlaceFitTree tree)
            {
                if (tree.inputs.Count > 0)
                {
                    var parentPos = GetLayoutNode(tree.node);
                    List <UNodeView> listNodes = new List <UNodeView>();
                    float            offset    = 0;
                    foreach (var childTree in tree.inputs)
                    {
                        PlaceFitNodes(childTree);
                        var nodes     = GetNodes(childTree);
                        var totalRect = GetNodeRect(nodes);

                        TeleportNodes(nodes, new Vector2(parentPos.x - totalRect.width - valueSpacing.x, parentPos.y + offset), false);
                        offset += totalRect.height + valueSpacing.y;
                        listNodes.AddRange(nodes);
                    }
                    if (tree.inputs.Count == 1)
                    {
                        var rect           = GetNodeRect(listNodes);
                        var sourcePosition = GetNodeRect(tree.inputs[0].node);
                        MoveNodes(listNodes, new Vector2(0, -(sourcePosition.y - rect.y) + (parentPos.height - sourcePosition.height) / 2));
                    }
                    else
                    {
                        MoveNodes(listNodes, new Vector2(0, ((parentPos.height - GetNodeRect(listNodes).height) / 2)));
                    }
                }
                if (tree.outputs.Count > 0)
                {
                    var parentPos = GetLayoutNode(tree.node);
                    List <UNodeView> listNodes = new List <UNodeView>();
                    float            offset    = 0;
                    foreach (var childTree in tree.outputs)
                    {
                        PlaceFitNodes(childTree);
                        var nodes     = GetNodes(childTree);
                        var totalRect = GetNodeRect(nodes);

                        TeleportNodes(nodes, new Vector2(parentPos.x + totalRect.width + valueSpacing.x, parentPos.y + offset), false);
                        offset += totalRect.height + valueSpacing.y;
                        listNodes.AddRange(nodes);
                    }
                    if (tree.outputs.Count == 1)
                    {
                        var rect           = GetNodeRect(listNodes);
                        var sourcePosition = GetNodeRect(tree.outputs[0].node);
                        MoveNodes(listNodes, new Vector2(0, -(sourcePosition.y - rect.y) + (parentPos.height - sourcePosition.height) / 2));
                    }
                    else
                    {
                        MoveNodes(listNodes, new Vector2(0, ((parentPos.height - GetNodeRect(listNodes).height) / 2)));
                    }
                }
                if (tree.flows.Count > 0)
                {
                    var   parentPos = GetNodeRect(tree.node);
                    float parentY   = parentPos.y + parentPos.height;
                    {
                        List <UNodeView> nodeViews = new List <UNodeView>();
                        if (tree.inputs.Count > 0)
                        {
                            foreach (var childTree in tree.inputs)
                            {
                                nodeViews.AddRange(GetNodes(childTree));
                            }
                        }
                        if (tree.outputs.Count > 0)
                        {
                            foreach (var childTree in tree.outputs)
                            {
                                nodeViews.AddRange(GetNodes(childTree));
                            }
                        }
                        if (nodeViews.Count > 0)
                        {
                            foreach (var n in nodeViews)
                            {
                                var rect = GetNodeRect(n);
                                if (rect.y + rect.height > parentY)
                                {
                                    parentY = rect.y + rect.height;
                                }
                            }
                        }
                    }
                    if (tree.flows.Count > 0)
                    {
                        List <UNodeView> listNodes = new List <UNodeView>();
                        float            offset    = 0;
                        foreach (var childTree in tree.flows)
                        {
                            PlaceFitNodes(childTree);
                            var nodes     = GetNodes(childTree);
                            var totalRect = GetLayoutNodes(nodes);
                            var dist      = Mathf.Abs(GetNodeRect(nodes).width - totalRect.width);

                            TeleportNodes(nodes, new Vector2(parentPos.x + offset + dist, parentY + flowSpacing.y), false);
                            offset += totalRect.width + flowSpacing.x + dist;
                            listNodes.AddRange(nodes);
                        }
                        if (tree.flows.Count == 1)
                        {
                            var rect           = GetNodeRect(listNodes);
                            var dist           = Mathf.Abs(rect.width - GetLayoutNodes(listNodes).width);
                            var sourcePosition = GetNodeRect(tree.flows[0].node);
                            //var parentPosition = GetNodeRect(tree.node);
                            //TeleportNodes(listNodes, new Vector2(parentPosition.x - (sourcePosition.x - rect.x) - ((sourcePosition.width - parentPos.width) / 2), rect.y), false);
                            MoveNodes(listNodes, new Vector2(-(sourcePosition.x - rect.x) + (parentPos.width - sourcePosition.width) / 2 - dist, 0));
                        }
                        else
                        {
                            var rect = GetNodeRect(listNodes);
                            var dist = Mathf.Abs(rect.width - GetLayoutNodes(listNodes).width);
                            MoveNodes(listNodes, new Vector2(((parentPos.width - rect.width) / 2) - dist, 0));
                        }
                    }
                }
            }