Version: 2019.1
public static Rect Window (int id, Rect screenRect, GUI.WindowFunction func, string text, params GUILayoutOption[] options);
public static Rect Window (int id, Rect screenRect, GUI.WindowFunction func, Texture image, params GUILayoutOption[] options);
public static Rect Window (int id, Rect screenRect, GUI.WindowFunction func, GUIContent content, params GUILayoutOption[] options);
public static Rect Window (int id, Rect screenRect, GUI.WindowFunction func, string text, GUIStyle style, params GUILayoutOption[] options);
public static Rect Window (int id, Rect screenRect, GUI.WindowFunction func, Texture image, GUIStyle style, params GUILayoutOption[] options);
public static Rect Window (int id, Rect screenRect, GUI.WindowFunction func, GUIContent content, GUIStyle style, params GUILayoutOption[] options);

パラメーター

idウィンドウごとのユニークな ID。これはウィンドウのインターフェースで使用します
screenRectウィンドウで使用するスクリーンの Rect。レイアウトシステムは screenRect の中にウィンドウが収まるようにします - もし収めることができない場合には、Rect を調整する必要があります
funcウィンドウの内側の GUI を作成する関数。この関数は GUI を作成するためのウィンドウの id をパラメーターとして持ちます
textウィンドウのタイトルとして表示されるテキスト
imageタイトルバー上に表示する Texture
contentウィンドウのテキスト、画像、ツールチップ
styleウィンドウに使用するスタイル。省略された場合は、現在の GUISkin にある toggle スタイルを使用します
optionsAn optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the style or the screenRect you pass in.
See Also: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

戻り値

Rect ウィンドウの Rect を返します。これは引数とし t 渡した値とは異なる位置とサイズと持つことができます。

説明

ウィンドウ内のコンテンツが自動でレイアウトされるポップアップウィンドウ

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:


Window in the Game View.

using UnityEngine;

public class ExampleScript : MonoBehaviour { Rect windowRect = new Rect(20, 20, 120, 50);

void OnGUI() { // Register the window. Notice the 3rd parameter windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window"); }

// Make the contents of the window void DoMyWindow(int windowID) { // This button will size to fit the window if (GUILayout.Button("Hello World")) { print("Got a click"); } } }

関数に渡すスクリーン Rect は、道案内のような役割として機能します。ウィンドウに特別な制限を適用するには、特別なレイアウトオプションを渡します。ここで適用されたオプションは計算されたサイズを上書きします。以下のような例です。

using UnityEngine;

public class ExampleScript : MonoBehaviour { Rect windowRect = new Rect(20, 20, 120, 50);

void 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 void DoMyWindow(int windowID) { // 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"); } } }