Beispiel #1
0
        // ----------------------------------------------------------------------
        // Returns the minimal distance from the parent.
        public float GetDistanceFromNode(iCS_EditorObject node, Vector2 point)
        {
            if (IsInside(node, point))
            {
                return(0);
            }
            Rect nodeRect = node.GlobalRect;

            if (point.x > nodeRect.xMin && point.x < nodeRect.xMax)
            {
                return(Mathf.Min(Mathf.Abs(point.y - nodeRect.yMin),
                                 Mathf.Abs(point.y - nodeRect.yMax)));
            }
            if (point.y > nodeRect.yMin && point.y < nodeRect.yMax)
            {
                return(Mathf.Min(Mathf.Abs(point.x - nodeRect.xMin),
                                 Mathf.Abs(point.x - nodeRect.xMax)));
            }
            float distance = Vector2.Distance(point, Math3D.TopLeftCorner(node.GlobalRect));

            distance = Mathf.Min(distance, Vector2.Distance(point, Math3D.TopRightCorner(node.GlobalRect)));
            distance = Mathf.Min(distance, Vector2.Distance(point, Math3D.BottomLeftCorner(node.GlobalRect)));
            distance = Mathf.Min(distance, Vector2.Distance(point, Math3D.BottomRightCorner(node.GlobalRect)));
            return(distance);
        }
        // -------------------------------------------------------------------------
        /// Draws a filled box with the given color.
        ///
        /// @param r The rectangle coordinate.
        /// @param color The color to use.
        ///
        public static void DrawFilledBox(Rect r, Color color)
        {
            var polygone = new Vector3[5];

            polygone[0] = Math3D.TopLeftCorner(r);
            polygone[1] = Math3D.TopRightCorner(r);
            polygone[2] = Math3D.BottomRightCorner(r);
            polygone[3] = Math3D.BottomLeftCorner(r);
            polygone[4] = Math3D.TopLeftCorner(r);
            var savedColor = Handles.color;

            Handles.color = color;
            Handles.DrawAAConvexPolygon(polygone);
            Handles.color = savedColor;
        }