返回介绍

GUI.Box 盒子

发布于 2019-12-18 15:37:45 字数 8576 浏览 1266 评论 0 收藏 0

JavaScript => public static function Box(position: Rect, text: string): void;
JavaScript => public static function Box(position: Rect, image: Texture): void;
JavaScript => public static function Box(position: Rect, content: GUIContent): void;
JavaScript => public static function Box(position: Rect, text: string, style: GUIStyle): void;
JavaScript => public static function Box(position: Rect, image: Texture, style: GUIStyle): void;
JavaScript => public static function Box(position: Rect, content: GUIContent, style: GUIStyle): void;

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

Parameters 参数

positionRectangle on the screen to use for the box.
用于盒子在屏幕上的矩形位置。
textText to display on the box.
在盒子上显示的文本
imageTexture to display on the box.
显示在盒子上的纹理图片
contentText, image and tooltip for this box.
用户盒子的文本,图片和提示信息
styleThe style to use. If left out, the box style from the current GUISkin is used.
使用的样式,如果不,盒子使用当前的GUISkin皮肤。

Description 描述

Create a Box on the GUI Layer. A Box can contain text, an image, or a combination of these along with an optional tooltip, through using a GUIContent parameter. You may also use a GUIStyle to adjust the layout of items in a box, text colour and other properties.

在界面布局创建盒子。盒子包含文本,图像或者带有工具提示的这些的组合,通过使用GUIContent参数。你也可以使用GUIStyle去调整盒子中所有的物体的布局,文本颜色和其他属性。

Here is an example of a Box containing Text:

这是关于盒子内容的例子:

JavaScript:

no example for javascript;

Here is an example of a Box containing a Texture: JavaScript:

no example for javascript;

Here is an example of a Box containing a GUIContent, combining Text, Texture and Tooltip: JavaScript:

no example for javascript;

Here is an example of a Box containing Text, with options set in a GUIStyle to position the Text in the center of the Box. JavaScript:

no example for javascript;

Here is an example of a Box containing a Texture, with options set in a GUIStyle to position the Texture in the center of the Box.

JavaScript:

no example for javascript;

Finally, here is an example of a Box containing a GUIContent, combining Text, Texture and Tooltip, with positional information contained in the GUIStyle parameter:

JavaScript:

no example for javascript;

Here is an example of a Box containing Text:

C#:

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: C#:

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

Here is an example of a Box containing a GUIContent, combining Text, Texture and Tooltip: C#:

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

Here is an example of a Box containing Text, with options set in a GUIStyle to position the Text in the center of the Box. C#:

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

Here is an example of a Box containing a Texture, with options set in a GUIStyle to position the Texture in the center of the Box.

C#:

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

Finally, here is an example of a Box containing a GUIContent, combining Text, Texture and Tooltip, with positional information contained in the GUIStyle parameter:

C#:

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

gui

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文