GUILayoutUtility.GetLastRect 获取上次使用的矩形

static function GetLastRect () : Rect

Returns

Rect - The last used rectangle.

返回Rect类型,上次使用的矩形。

Description描述

Get the rectangle last used by GUILayout for a control.

获取一个控件由GUILayout使用的最后一个矩形。

Note that this only works during the Repaint event.

请注意,这个仅工作在Repaint事件期间。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void OnGUI() {
	GUILayout.Button("My button");
	if (Event.current.type == EventType.Repaint && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
		GUILayout.Label("Mouse over!");
	else
		GUILayout.Label("Mouse somewhere else");
	}
}
function OnGUI() {
	GUILayout.Button( "My button" );
	if(Event.current.type == EventType.Repaint &&
	GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition )) {
		GUILayout.Label( "Mouse over!" );
	} else {
		GUILayout.Label( "Mouse somewhere else" );
	}
}
Page last updated: 2011-1-3