public static WorldPointToSizedRect ( Vector3 position, |
||
position | Vector3 | The world-space position to use. |
content | The content to make room for. | |
style | The style to use. The style's alignment. | |
return |
public static Rect WorldPointToSizedRect(Vector3 position, GUIContent content, GUIStyle style)
{
Vector2 vector = WorldToGUIPoint(position);
Vector2 vector2 = style.CalcSize(content);
Rect rect = new Rect(vector.x, vector.y, vector2.x, vector2.y);
switch (style.alignment)
{
case TextAnchor.UpperCenter:
rect.xMin -= rect.width * 0.5f;
break;
case TextAnchor.UpperRight:
rect.xMin -= rect.width;
break;
case TextAnchor.MiddleLeft:
rect.yMin -= rect.height * 0.5f;
break;
case TextAnchor.MiddleCenter:
rect.xMin -= rect.width * 0.5f;
rect.yMin -= rect.height * 0.5f;
break;
case TextAnchor.MiddleRight:
rect.xMin -= rect.width;
rect.yMin -= rect.height * 0.5f;
break;
case TextAnchor.LowerLeft:
rect.yMin -= rect.height * 0.5f;
break;
case TextAnchor.LowerCenter:
rect.xMin -= rect.width * 0.5f;
rect.yMin -= rect.height;
break;
case TextAnchor.LowerRight:
rect.xMin -= rect.width;
rect.yMin -= rect.height;
break;
}
return style.padding.Add(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); } }