GUILayoutUtility.GetRect 获取矩形
static function GetRect (content : GUIContent, style : GUIStyle) : Rect
static function GetRect (content : GUIContent, style : GUIStyle, params options : GUILayoutOption[]) : Rect
Parameters参数
-
contentThe content to make room for displaying
为显示内容以让出空间 -
styleThe GUIStyle to layout for.
用于布局内容的GUIStyle
-
optionsAn optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the style.
布局选项的一个可选列表,指定额外的布局属性。这里传递任意值将覆盖由style定义的设置。
Rect - A rectangle that is large enough to contain content when rendered in style.
返回Rect类型,一个足够大矩形包含style渲染的content内容。
Description描述
Reserve layout space for a rectangle for displaying some contents with a specific style.
为显示某些对于一个指定风格的内容的矩形,保留布局空间。也就是说,获取一个自动大小矩形。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public GUIContent buttonText = new GUIContent("some button");
public GUIStyle buttonStyle = GUIStyle.none;
void OnGUI() {
Rect rt = GUILayoutUtility.GetRect(buttonText, buttonStyle);
if (rt.Contains(Event.current.mousePosition))
GUI.Label(new Rect(0, 20, 200, 70), "PosX: " + rt.x + "\nPosY: " + rt.y + "\nWidth: " + rt.width + "\nHeight: " + rt.height);
GUI.Button(rt, buttonText, buttonStyle);
}
}
// Shows the button rect properties in a label when the mouse is over it
//当鼠标经过时,在标签显示按钮的矩形属性
var buttonText : GUIContent = new GUIContent("some dasdfgwbutton");
var buttonStyle : GUIStyle = GUIStyle.none;
function OnGUI() {
var rt : Rect = GUILayoutUtility.GetRect(buttonText, buttonStyle);
if (rt.Contains(Event.current.mousePosition)) {
GUI.Label(Rect(0,20,200,70), "PosX: " + rt.x + "\nPosY: " + rt.y +
"\nWidth: " + rt.width + "\nHeight: " + rt.height);
}
GUI.Button(rt, buttonText, buttonStyle);
}
• static function GetRect (width : float, height : float) : Rect
• static function GetRect (width : float, height : float, style : GUIStyle) : Rect
• static function GetRect (width : float, height : float, params options : GUILayoutOption[]) : Rect
• static function GetRect (width : float, height : float, style : GUIStyle, params options : GUILayoutOption[]) : Rect
Parameters参数
-
widthThe width of the area you want.
你想要区域的宽度 -
heightThe height of the area you want.
你想要区域的高度 -
styleAn optional GUIStyle to layout for. If specified, the style's padding value will be added to your sizes & its margin value will be used for spacing.
用于布局的可选GUIStyle。如果指定,该style的padding值将加到你的大小,并且margin值将用于外边距。 -
optionsAn optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the style.
布局选项的一个可选列表,指定额外的布局属性。这里传递任意值将覆盖由style定义的设置。
参见: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.
Rect - The rectanlge to put your control in.
返回Rect类型,放置你的控件的矩形。
Description描述
Reserve layout space for a rectangle with a fixed content area.
为一个固定内容区域的矩形,保留布局空间。也就是说,获取一个固定大小的矩形。
• static function GetRect (minWidth : float, maxWidth : float, minHeight : float, maxHeight : float) : Rect
• static function GetRect (minWidth : float, maxWidth : float, minHeight : float, maxHeight : float, style : GUIStyle) : Rect
• static function GetRect (minWidth : float, maxWidth : float, minHeight : float, maxHeight : float, params options : GUILayoutOption[]) : Rect
• static function GetRect (minWidth : float, maxWidth : float, minHeight : float, maxHeight : float, style : GUIStyle, params options : GUILayoutOption[]) : Rect
Parameters参数
-
minWidthThe minimum width of the area passed back.
传回区域的最小宽度 -
maxWidthThe maximum width of the area passed back.
传回区域的最大宽度 -
minHeightThe minimum width of the area passed back.
传回区域的最新高度 -
maxHeightThe maximum width of the area passed back.
传回区域的最大高度 -
styleAn optional GUIStyle to layout for. If specified, the style's padding value will be added to your sizes & its margin value will be used for spacing.
用于布局的可选GUIStyle。如果指定,该style的padding值将加到你的大小,并且margin值将用于外边距。 -
optionsAn optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the style.
布局选项的一个可选列表,指定额外的布局属性。这里传递任意值将覆盖由style定义的设置。
参见: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.
Rect - a rectangle with size between minWidth & maxWidth on both axes
返回Rect类型,一个矩形大小在两个轴上最小值和最大值之间。
Description描述
Reserve layout space for a flexible rect.
为液态矩形保留布局空间;通俗的说,返回一个大小在最小和最大值之间的液态矩形。
The rectangle's size will be between the min & max values.
矩形的大小在min和max值之间。