GUILayoutUtility.GetRectstatic function GetRect (content : GUIContent, style : GUIStyle) : Rectstatic function GetRect (content : GUIContent, style : GUIStyle, params options : GUILayoutOption[]) : RectParameters
ReturnsRect - A rectangle that is large enough to contain content when rendered in style. DescriptionReserve layout space for a rectangle for displaying some contents with a specific style.
JavaScripts
// Shows the button rect properties in a label when the mouse is over it
var buttonText : GUIContent = new GUIContent("some button"); 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); } 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); } } import UnityEngine
import System.Collections class example(MonoBehaviour): public buttonText as GUIContent = GUIContent('some button') public buttonStyle as GUIStyle = GUIStyle.none def OnGUI(): rt as 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) : Rectstatic function GetRect (width : float, height : float, params options : GUILayoutOption[]) : Rectstatic function GetRect (width : float, height : float, style : GUIStyle, params options : GUILayoutOption[]) : RectParameters
ReturnsRect - The rectanlge to put your control in. DescriptionReserve layout space for a rectangle with a fixed content area. static function GetRect (minWidth : float, maxWidth : float, minHeight : float, maxHeight : float) : Rectstatic function GetRect (minWidth : float, maxWidth : float, minHeight : float, maxHeight : float, style : GUIStyle) : Rectstatic function GetRect (minWidth : float, maxWidth : float, minHeight : float, maxHeight : float, params options : GUILayoutOption[]) : Rectstatic function GetRect (minWidth : float, maxWidth : float, minHeight : float, maxHeight : float, style : GUIStyle, params options : GUILayoutOption[]) : RectParameters
ReturnsRect - a rectangle with size between minWidth & maxWidth on both axes DescriptionReserve layout space for a flexible rect. The rectangle's size will be between the min & max values. |
