예제 #1
0
        void DrawRectConnection(Rect rectA, Rect rectB, bool highlight)
        {
            Vector2 pointA;
            Vector2 pointB;

            Vector2 p1 = rectA.center;
            Vector2 p2 = rectB.center;

            GLDraw.segment_rect_intersection(rectA, ref p1, ref p2);
            pointA = p2;

            p1 = rectB.center;
            p2 = rectA.center;
            GLDraw.segment_rect_intersection(rectB, ref p1, ref p2);
            pointB = p2;

            Color color = Color.grey;

            if (highlight)
            {
                color = Color.green;
            }

            GLDraw.DrawConnectingCurve(pointA, pointB, color, 2);
        }
        protected virtual void DrawRectConnection(Rect rectA, Rect rectB, bool highlight)
        {
            Vector2[] pointsA = new Vector2[] {
                new Vector2(rectA.xMin + 5, rectA.center.y),
                new Vector2(rectA.xMin + rectA.width / 2, rectA.yMin + 2),
                new Vector2(rectA.xMin + rectA.width / 2, rectA.yMax - 2),
                new Vector2(rectA.xMax - 5, rectA.center.y)
            };

            Vector2[] pointsB = new Vector2[] {
                new Vector2(rectB.xMin + 5, rectB.center.y),
                new Vector2(rectB.xMin + rectB.width / 2, rectB.yMin + 2),
                new Vector2(rectB.xMin + rectB.width / 2, rectB.yMax - 2),
                new Vector2(rectB.xMax - 5, rectB.center.y)
            };

            Vector2 pointA  = Vector2.zero;
            Vector2 pointB  = Vector2.zero;
            float   minDist = float.MaxValue;

            foreach (Vector2 a in pointsA)
            {
                foreach (Vector2 b in pointsB)
                {
                    float d = Vector2.Distance(a, b);
                    if (d < minDist)
                    {
                        pointA  = a;
                        pointB  = b;
                        minDist = d;
                    }
                }
            }

            Color color = Color.grey;

            if (highlight)
            {
                color = Color.green;
            }

            GLDraw.DrawConnectingCurve(pointA, pointB, color, 1.025f);

            Rect dotARect = new Rect(pointA.x - 5, pointA.y - 5, 10, 10);

            GUI.Label(dotARect, "", new GUIStyle("U2D.dragDotActive"));

            Rect dotBRect = new Rect(pointB.x - 5, pointB.y - 5, 10, 10);

            GUI.Label(dotBRect, "", new GUIStyle("U2D.dragDotActive"));
        }