Begounet / unity-dependency-graph-viewer

Visual graph in editor to see dependencies/references of an asset on Unity (based on UE4 reference viewer)
MIT License
36 stars 6 forks source link

Nodes on right side of graph aren't centered #2

Open sambonfire opened 5 years ago

sambonfire commented 5 years ago

It looks like the code to center the nodes on the right side of the graph isn't working correctly. For me these nodes were often offset at odd angles. I changed this method to fix it:

        private void CenterTreeToRoot(Node.NodeInputSide side)
        {
            var children = _refTargetNode.GetChildren(side);

            if (children.Count > 1)
            {
                float refTargetY = _refTargetNode.Position.y;
                float size = _refTargetNode.GetLastChild(side).Position.y -
                             _refTargetNode.GetFirstChild(side).Position.y;
                float actualY = _refTargetNode.GetFirstChild(side).Position.y;
                float desiredY = refTargetY - size/2.0f;
                float shiftY = desiredY - actualY;

                for (int i = 0; i < children.Count; ++i)
                {
                    children[i].ForeachChildrenRecursively(side, (node) => node.SetPositionY(node.Position.y + shiftY));
                }
            }
        }
Begounet commented 5 years ago

Hello!

I will completely trust you and add it into the plugin. I won't tell that I had no idea of what I was doing but I tried to implement an algorithm that I did not fully understood...

So, thanks you for your contribution! It is now available on master.