Мои Уведомления
Привет, !
Мой Аккаунт Мои Финансы Мои Подписки Мои Настройки Выход
Руководство API скрипты

Объявление

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);

Параметры

position Прямоугольник на экране, чтобы использовать для коробки.
text Текст для отображения на поле.
image Текстура для отображения на поле.
content Текст, изображение и всплывающая подсказка для этого поля.
style Используемый стиль. Если его не указать, используется стиль box из текущего GUISkin.

Описание

Создайте поле на слое графического интерфейса пользователя.

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

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

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

Here is an example of a Box containing a Texture:

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); } }

Вот пример окна, содержащего GUIContent, объединяющего текст, текстуру и всплывающую подсказку:

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); } }

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

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); } }

Наконец, вот пример блока, содержащего GUIContent, объединяющего текст, текстуру и всплывающую подсказку, с информацией о местоположении, содержащейся в параметре 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); } }
Вы можете отблагодарить автора, за перевод документации на русский язык. ₽ Спасибо
API скрипты 2021.3