GUI.BeginGroup 开始组

static function BeginGroup (position : Rect) : void
static function BeginGroup (position : Rect, text : string) : void
static function BeginGroup (position : Rect, image : Texture) : void
static function BeginGroup (position : Rect, content : GUIContent) : void
static function BeginGroup (position : Rect, style : GUIStyle) : void
static function BeginGroup (position : Rect, text : string, style : GUIStyle) : void
static function BeginGroup (position : Rect, image : Texture, style : GUIStyle) : void
static function BeginGroup (position : Rect, content : GUIContent, style : GUIStyle) : void

Parameters参数

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.

当你在屏幕上移动一批GUI元素的时候,使用组将非常有用,一个常见的用例是设计你的菜单适配特殊的屏幕分辨率,然后,GUI在大显示器上居中对齐。

另见: matrix, BeginScrollView.

using UnityEngine;
using System.Collections;

public class example : 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();
	}
}
function OnGUI () {
	//在屏幕上约束所有元件在800x600像素的区域内。
	GUI.BeginGroup(new Rect(Screen.width / 2 - 400, Screen.height / 2 - 300, 800, 600));

	//绘制一个box,注意坐标是基于BeginGroup的
	GUI.Box(new Rect(0,0,800,600),	"This box is now centered! - here you would put your main menu");

	//这个组是成对出现的,所以需要EndGroup来结束这个容器。
	GUI.EndGroup();
} 
Page last updated: 2011-6-15