Example #1
0
        internal static Transform2d Draw(IEnumerable <Vector2> vertexPositions, Rect drawRect, Rect viewRect, bool showGraphBounds, MinimapStyle style)
        {
            // draw black outline
            EditorGUI.DrawRect(drawRect.AddBorder(1f), Color.black);
            // draw background
            EditorGUI.DrawRect(drawRect, style.backgroundColor);

            // fit vertex positions and viewRect into drawRect
            var pointsToFit = vertexPositions.Concat(
                new[] {
                new Vector2(viewRect.xMin, viewRect.yMin),
                new Vector2(viewRect.xMax, viewRect.yMax)
            });

            var mmTransform = ViewUtil.FitPointsIntoRect(pointsToFit, drawRect.Scale(0.9f));

            // draw view rect
            Rect tViewRect = mmTransform.Apply(viewRect).Intersection(drawRect);

            Util.DrawRectOutline(tViewRect, style.viewRectColor);

            // draw vertex positions
            foreach (var pos in vertexPositions)
            {
                EditorGUI.DrawRect(Util.CenterRect(mmTransform.Apply(pos), 2, 2), style.vertexMarkerColor);
            }

            return(mmTransform);
        }
Example #2
0
        // set the transform such that it can display the whole graph in the parent rect
        public Transform2d GetOptimalTransform()
        {
            var entityPositions = graph.VerticesData.Values.Select(v => v.pos);

            // use only the center area of the view rect for displaying the graph
            Rect viewRect  = parent.GetViewRect();
            Rect graphRect = Util.CenterRect(viewRect.center, viewRect.GetExtents() * 0.7f);

            return(ViewUtil.FitPointsIntoRect(entityPositions, graphRect));
        }