Unity 6.3
0 онлайн 2 гостей 3 в системе
Вход

GUI.Window

Declaration

public static Rect Window(int id, Rect clientRect, GUI.WindowFunction func, string text);
public static Rect Window(int id, Rect clientRect, GUI.WindowFunction func, Texture image);
public static Rect Window(int id, Rect clientRect, GUI.WindowFunction func, GUIContent content);
public static Rect Window(int id, Rect clientRect, GUI.WindowFunction func, string text, GUIStyle style);
public static Rect Window(int id, Rect clientRect, GUI.WindowFunction func, Texture image, GUIStyle style);
public static Rect Window(int id, Rect clientRect, GUI.WindowFunction func, GUIContent title, GUIStyle style);

Параметры

Параметр Описание
Стиль Необязательный стиль для использования в окне. Если этот параметр не указан, используется стиль window из текущих стилей GUISkin.
Идентификатор ID номер окна (может быть любым значением, если оно уникально).
clientRect Экранный прямоугольник, обозначающий положение и размер окна.
Функции Функция скрипта для отображения содержимого окна.
текст Текст для отображения внутри окна.
изображение Изображение для отображения внутри окна.
содержание GUIContent для рендеринга внутри окна.
стиль Информация о стиле окна.
название Текст, отображаемый в заголовке окна.

Возвращаемое значение

Прямая Прямоугольник на экране, обозначающий положение и размер окна.

Описание

Сделать всплывающее окно.

Windows поплавок выше нормального GUI контроли, особенность щелкните-к-фокусу и могут по желанию быть перетянуты вокруг конечным пользователем. Не похож на другие контроли, вам нужно пройти им отдельную функцию которая делает GUI управления внутри окна.

Примечание: Если вы используете GUILayout для размещения компонентов внутри окна, вы должны использовать GUILayout.WindowКроме того, если MonoBehaviour.useGUILayout установлен в false, то вызов GUI.Window не будет иметь никаких последствий, хотя это и не является GUILayout функции.

using UnityEngine;
using System.Collections;

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

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

// Make the contents of the window void DoMyWindow(int windowID) { if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World")) { print("Got a click"); } } }

Вы можете использовать одну и ту же функцию для создания нескольких окон. Просто убедитесь, что каждое окно имеет собственное ID. Пример:

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Rect windowRect0 = new Rect(20, 20, 120, 50); public Rect windowRect1 = new Rect(20, 100, 120, 50);

void OnGUI() { // Register the window. We create two windows that use the same function // Notice that their IDs differ windowRect0 = GUI.Window(0, windowRect0, DoMyWindow, "My Window"); windowRect1 = GUI.Window(1, windowRect1, DoMyWindow, "My Window"); }

// Make the contents of the window void DoMyWindow(int windowID) { if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World")) { print("Got a click in window " + windowID); }

// Make the windows be draggable. GUI.DragWindow(new Rect(0, 0, 10000, 10000)); } }

Чтобы прекратить показ окна, просто прекратите вызов GUI.Window из вашей основной функции OnGUI:

// boolean variable to decide whether to show the window or not.
// Change this from the in-game GUI, scripting, the inspector or anywhere else to
// decide whether the window is visible

using UnityEngine; using System.Collections;

public class ExampleClass : MonoBehaviour { public bool doWindow0 = true;

// Make the contents of the window. void DoWindow0(int windowID) { GUI.Button(new Rect(10, 30, 80, 20), "Click Me!"); }

void OnGUI() { // Make a toggle button for hiding and showing the window doWindow0 = GUI.Toggle(new Rect(10, 10, 100, 20), doWindow0, "Window 0");

// Make sure we only call GUI.Window if doWindow0 is true. if (doWindow0) { GUI.Window(0, new Rect(110, 10, 200, 60), DoWindow0, "Basic Window"); } } }

Чтобы создать окно, размер которого определяется автоматически GUI макетирование, использование GUILayout.Window. Заказ звонков Windows окна, расположенные сверху других окон, должны рисоваться позже, чем окна, расположенные под ними. Это означает, что вы не можете рассчитывать на то, что ваши окна будут рисоваться позже, чем окна, расположенные DoWindow Для того, чтобы это работало беспрепятственно, следующие значения сохраняются при создании окна (с помощью команды "create window" в командной строке). Окно функции), и извлекается, когда ваш DoWindow получает вызов: GUI.skin, GUI.enabled, GUI.color, GUI.backgroundColor, GUI.contentColor, GUI.matrix.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Rect windowRect0 = new Rect(20, 20, 120, 50); public Rect windowRect1 = new Rect(20, 100, 120, 50);

void OnGUI() { // Here we make 2 windows. We set the GUI.color value to something before each. GUI.color = Color.red; windowRect0 = GUI.Window(0, windowRect0, DoMyWindow, "Red Window");

GUI.color = Color.green; windowRect1 = GUI.Window(1, windowRect1, DoMyWindow, "Green Window"); }

// Make the contents of the window. // The value of GUI.color is set to what it was when the window // was created in the code above. void DoMyWindow(int windowID) { if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World")) { print("Got a click in window with color " + GUI.color); }

// Make the windows be draggable. GUI.DragWindow(new Rect(0, 0, 10000, 10000)); } }

Обратите внимание, что вы можете использовать альфа-компонент GUI.color для плавного ввода и вывода окон.

Дополнительные ресурсы: DragWindow, BringWindowToFront, BringWindowToBack.