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

GUI.Box

Declaration

public static void Box(Rect position, string text);
public static void Box(Rect position, Texture image);
public static void Box(Rect position, GUIContent content);
public static void Box(Rect position, string text, GUIStyle style);
public static void Box(Rect position, Texture image, GUIStyle style);
public static void Box(Rect position, GUIContent content, GUIStyle style);

Параметры

Параметр Описание
должность Прямоугольник на экране для использования для коробки.
текст Текст для отображения в поле.
изображение Texture для отображения на коробке.
содержание Текст, изображение и tooltip для этого поля.
стиль Используемый стиль. Если этот параметр не указан, то используется стиль box из текущего GUISkin.

Описание

Создайте коробку на слое GUI.

Блок может содержать текст, изображение или их комбинацию вместе с дополнительным параметром tooltip, используя параметры GUIContent. Вы также можете использовать параметры GUIStyle для настройки расположения элементов в блоке, цвета текста и других свойств.

Вот пример Блока, содержащего Текст:

using UnityEngine;

public class BoxExample : MonoBehaviour { void OnGUI() { GUI.Box(new Rect(0, 0, Screen.width, Screen.height), "This is a box"); } }

Вот пример Коробки, содержащей Текстуру:

using UnityEngine;

public class BoxWithTextureExample : MonoBehaviour { public Texture BoxTexture; // Drag a Texture onto this item in the Inspector

void OnGUI() { GUI.Box(new Rect(0, 0, Screen.width, Screen.height), BoxTexture); } }

Вот пример Box, содержащий GUIContent, сочетающий в себе Text, Texture и Tooltip:

using UnityEngine;

public class BoxWithContentExample : MonoBehaviour { public Texture BoxTexture; // Drag a Texture onto this item in the Inspector

GUIContent content;

void Start() { content = new GUIContent("This is a box", BoxTexture, "This is a tooltip"); }

void OnGUI() { GUI.Box(new Rect(0, 0, Screen.width, Screen.height), content); } }

Здесь приведен пример Блока, содержащего Текст, с параметрами, установленными в GUIStyle для размещения Текста в центре Блока.

using UnityEngine;

public class BoxWithTextStyleExample : MonoBehaviour { GUIStyle style = new GUIStyle();

void Start() { // Position the Text in the center of the Box style.alignment = TextAnchor.MiddleCenter; }

void OnGUI() { GUI.Box(new Rect(0, 0, Screen.width, Screen.height), "This is a box", style); } }

Вот пример Box, содержащего Текстуру, с параметрами, установленными в GUIStyle для размещения Текстуры в центре Box.

using UnityEngine;

public class BoxWithTextureStyleExample : MonoBehaviour { public Texture BoxTexture; // Drag a Texture onto this item in the Inspector

GUIStyle style = new GUIStyle();

void Start() { // Position the Texture in the center of the Box style.alignment = TextAnchor.MiddleCenter; }

void OnGUI() { GUI.Box(new Rect(0, 0, Screen.width, Screen.height), BoxTexture, style); } }

Наконец, вот пример Box, содержащий GUIContent, сочетающий в себе Text, Texture и Tooltip, с позиционной информацией, содержащейся в параметре GUIStyle:

using UnityEngine;

public class BoxWithContentStyleExample : MonoBehaviour { public Texture BoxTexture; // Drag a Texture onto this item in the Inspector

GUIContent content; GUIStyle style = new GUIStyle();

void Start() { content = new GUIContent("This is a box", BoxTexture, "This is a tooltip");

// Position the Text and Texture in the center of the box style.alignment = TextAnchor.MiddleCenter;

// Position the Text below the Texture (rather than to the right of it) style.imagePosition = ImagePosition.ImageAbove; }

void OnGUI() { GUI.Box(new Rect(0, 0, Screen.width, Screen.height), content, style); } }