GUILayout.Windowstatic function Window (id : int, screenRect : Rect, func : GUI.WindowFunction, text : String, : ) : Rectstatic function Window (id : int, screenRect : Rect, func : GUI.WindowFunction, image : Texture, : ) : Rectstatic function Window (id : int, screenRect : Rect, func : GUI.WindowFunction, content : GUIContent, : ) : Rectstatic function Window (id : int, screenRect : Rect, func : GUI.WindowFunction, text : String, style : GUIStyle, : ) : Rectstatic function Window (id : int, screenRect : Rect, func : GUI.WindowFunction, image : Texture, style : GUIStyle, : ) : Rectstatic function Window (id : int, screenRect : Rect, func : GUI.WindowFunction, content : GUIContent, style : GUIStyle, : ) : RectParameters
ReturnsRect - the rectangle the window is at. This can be in a different position and have a different size than the one you passed in. DescriptionMake a popup window that layouts its contents automatically. Windows float above normal GUI controls, feature click-to-focus and can optionally be dragged around by the end user. Unlike other controls, you need to pass them a separate function for the GUI controls to put inside the window. Here is a small example to get you started:
JavaScripts
var windowRect : Rect = Rect (20, 20, 120, 50);
function OnGUI () { // Register the window. Notice the 3rd parameter windowRect = GUILayout.Window (0, windowRect, DoMyWindow, "My Window"); } // Make the contents of the window function DoMyWindow (windowID : int) { // This button will size to fit the window if (GUILayout.Button ("Hello World")) print ("Got a click"); } using UnityEngine;
using System.Collections; public class example : MonoBehaviour { public Rect windowRect = new Rect(20, 20, 120, 50); void OnGUI() { windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window"); } void DoMyWindow(int windowID) { if (GUILayout.Button("Hello World")) print("Got a click"); } } import UnityEngine
import System.Collections class example(MonoBehaviour): public windowRect as Rect = Rect(20, 20, 120, 50) def OnGUI(): windowRect = GUILayout.Window(0, windowRect, DoMyWindow, 'My Window') def DoMyWindow(windowID as int): if GUILayout.Button('Hello World'): print('Got a click') The screen rectangle you pass in to the function only acts as a guide. To Apply extra limits to the window, pass in some extra layout options. The ones applied here will override the size calculated. Here is a small example:
JavaScripts
var windowRect : Rect = Rect (20, 20, 120, 50);
function OnGUI () { // Register the window. Here we instruct the layout system to // make the window 100 pixels wide no matter what. windowRect = GUILayout.Window ( 0, windowRect, DoMyWindow, "My Window", GUILayout.Width (100)); } // Make the contents of the window function DoMyWindow (windowID : int) { // This button is too large to fit the window // Normally, the window would have been expanded to fit the button, but due to // the GUILayout.Width call above the window will only ever be 100 pixels wide if (GUILayout.Button ("Please click me a lot")) print ("Got a click"); } using UnityEngine;
using System.Collections; public class example : MonoBehaviour { public Rect windowRect = new Rect(20, 20, 120, 50); void OnGUI() { windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window", GUILayout.Width(100)); } void DoMyWindow(int windowID) { if (GUILayout.Button("Please click me a lot")) print("Got a click"); } } import UnityEngine
import System.Collections class example(MonoBehaviour): public windowRect as Rect = Rect(20, 20, 120, 50) def OnGUI(): windowRect = GUILayout.Window(0, windowRect, DoMyWindow, 'My Window', GUILayout.Width(100)) def DoMyWindow(windowID as int): if GUILayout.Button('Please click me a lot'): print('Got a click')
|

