WorldPointToSizedRect() public static method

Calculate a rectangle to display a 2D GUI element near a projected point in 3D space.

public static WorldPointToSizedRect ( Vector3 position, GUIContent content, GUIStyle style ) : Rect
position Vector3 The world-space position to use.
content UnityEngine.GUIContent The content to make room for.
style UnityEngine.GUIStyle The style to use. The style's alignment.
return UnityEngine.Rect
        private static void DrawPoseError(Transform node, Bounds bounds)
        {
            Camera current = Camera.current;

            if (current)
            {
                GUIStyle gUIStyle = new GUIStyle(GUI.skin.label);
                gUIStyle.normal.textColor = Color.red;
                gUIStyle.wordWrap         = false;
                gUIStyle.alignment        = TextAnchor.MiddleLeft;
                Vector3 position = node.position;
                Vector3 vector   = node.position + Vector3.up * 0.2f;
                if (node.position.x <= node.root.position.x)
                {
                    vector.x = bounds.min.x;
                }
                else
                {
                    vector.x = bounds.max.x;
                }
                GUIContent content   = new GUIContent(node.name);
                Rect       position2 = HandleUtility.WorldPointToSizedRect(vector, content, gUIStyle);
                position2.x += 2f;
                if (node.position.x > node.root.position.x)
                {
                    position2.x -= position2.width;
                }
                Handles.BeginGUI();
                position2.y -= gUIStyle.CalcSize(content).y / 4f;
                GUI.Label(position2, content, gUIStyle);
                Handles.EndGUI();
                Handles.color = AvatarSkeletonDrawer.kErrorMessageColor;
                Handles.DrawLine(position, vector);
            }
        }
 private static void DrawPoseError(Transform node, Bounds bounds)
 {
     if (Camera.current != null)
     {
         GUIStyle style = new GUIStyle(GUI.skin.label)
         {
             normal    = { textColor = Color.red },
             wordWrap  = false,
             alignment = TextAnchor.MiddleLeft
         };
         Vector3 position = node.position;
         Vector3 vector2  = node.position + ((Vector3)(Vector3.up * 0.2f));
         if (node.position.x <= node.root.position.x)
         {
             vector2.x = bounds.min.x;
         }
         else
         {
             vector2.x = bounds.max.x;
         }
         GUIContent content = new GUIContent(node.name);
         Rect       rect    = HandleUtility.WorldPointToSizedRect(vector2, content, style);
         rect.x += 2f;
         if (node.position.x > node.root.position.x)
         {
             rect.x -= rect.width;
         }
         Handles.BeginGUI();
         rect.y -= style.CalcSize(content).y / 4f;
         GUI.Label(rect, content, style);
         Handles.EndGUI();
         Handles.color = kErrorMessageColor;
         Handles.DrawLine(position, vector2);
     }
 }
示例#3
0
        private static void DrawPoseError(Transform node, Bounds bounds)
        {
            if (!(bool)((Object)Camera.current))
            {
                return;
            }
            GUIStyle style = new GUIStyle(GUI.skin.label);

            style.normal.textColor = Color.red;
            style.wordWrap         = false;
            style.alignment        = TextAnchor.MiddleLeft;
            Vector3 position = node.position;
            Vector3 vector3  = node.position + Vector3.up * 0.2f;

            vector3.x = (double)node.position.x > (double)node.root.position.x ? bounds.max.x : bounds.min.x;
            GUIContent content   = new GUIContent(node.name);
            Rect       sizedRect = HandleUtility.WorldPointToSizedRect(vector3, content, style);

            sizedRect.x += 2f;
            if ((double)node.position.x > (double)node.root.position.x)
            {
                sizedRect.x -= sizedRect.width;
            }
            Handles.BeginGUI();
            sizedRect.y -= style.CalcSize(content).y / 4f;
            GUI.Label(sizedRect, content, style);
            Handles.EndGUI();
            Handles.color = AvatarSkeletonDrawer.kErrorMessageColor;
            Handles.DrawLine(position, vector3);
        }
        private static void DrawPoseError(Transform node, Bounds bounds)
        {
            Camera camera = Camera.current;

            if (camera)
            {
                GUIStyle style = new GUIStyle(GUI.skin.label);
                style.normal.textColor = Color.red;
                style.wordWrap         = false;
                style.alignment        = TextAnchor.MiddleLeft;

                Vector3 start = node.position;
                Vector3 end   = node.position + Vector3.up * 0.20f;
                if (node.position.x <= node.root.position.x)
                {
                    end.x = bounds.min.x;
                }
                else
                {
                    end.x = bounds.max.x;
                }

                GUIContent content = new GUIContent(node.name);
                Rect       rect    = HandleUtility.WorldPointToSizedRect(end, content, style);
                rect.x += 2;
                if (node.position.x > node.root.position.x)
                {
                    rect.x -= rect.width;
                }

                Handles.BeginGUI();
                rect.y -= style.CalcSize(content).y / 4;
                GUI.Label(rect, content, style);
                Handles.EndGUI();

                Handles.color = kErrorMessageColor;
                Handles.DrawLine(start, end);
            }
        }