返回介绍

GUI.BeginGroup 开始组

发布于 2019-12-18 15:37:44 字数 4813 浏览 1268 评论 0 收藏 0

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

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

Parameters 参数

positionRectangle on the screen to use for the group.
用于组在屏幕上矩形的位置
textText to display on the group.
在组上显示的文本
imageTexture to display on the group.
在组上显示的纹理图片
contentText, image and tooltip for this group. If supplied, any mouse clicks are “captured” by the group and not If left out, no background is rendered, and mouse clicks are passed.
用于组的文本,图片和提示,如果提供,任意鼠标点击被组捕获,如果不提供,不会渲染背景和传递鼠标点击。
styleThe style to use for the background.
用于背景的样式。

Description 描述

Begin a group. Must be matched with a call to EndGroup.

开始组,必须配套以EndGroup结束关闭容器。

When you begin a group, the coordinate system for GUI controls are set so (0,0) is the top-left corner of the group. All controls are clipped to the group. Groups can be nested - if they are, children are clipped to their parents.

当你开始创建一个组,里面的GUI控件的坐标系统相对于组的左上角设置为0,0,所有的控件被限制到该组,组可以嵌套,子组将依附于父组。

This is very useful when moving a bunch of GUI elements around on screen. A common use case is designing your menus to fit on a specific screen size, then centering the GUI on larger displays. See Also: matrix, BeginScrollView.

当你开始创建一个组,里面的GUI控件的坐标系统相对于组的左上角设置为0,0,所有的控件被限制到该组,组可以嵌套,子组将依附于父组。

JavaScript:

function OnGUI () {
		// Constrain all drawing to be within a 800x600 pixel area centered on the screen.
		GUI.BeginGroup (new Rect (Screen.width / 2 - 400, Screen.height / 2 - 300, 800, 600));
 
		// Draw a box in the new coordinate space defined by the BeginGroup.
		// Notice how (0,0) has now been moved on-screen
		GUI.Box (new Rect (0,0,800,600),
			"This box is now centered! - here you would put your main menu");
 
		// We need to match all BeginGroup calls with an EndGroup
		GUI.EndGroup ();
	}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void OnGUI() {
        GUI.BeginGroup(new Rect(Screen.width / 2 - 400, Screen.height / 2 - 300, 800, 600));
        GUI.Box(new Rect(0, 0, 800, 600), "This box is now centered! - here you would put your main menu");
        GUI.EndGroup();
    }
}

gui

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

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

发布评论

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