GUILayoutUtility.GetRect 获取矩形

static function GetRect (content : GUIContent, style : GUIStyle) : Rect
static function GetRect (content : GUIContent, style : GUIStyle, params options : GUILayoutOption[]) : Rect

Parameters参数

Returns

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参数

Returns

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参数

Returns

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值之间。

Page last updated: 2011-1-3