GUILayout.Window 窗口

static function Window (id : int, screenRect : Rect, func : GUI.WindowFunction, text : string, : ) : Rect
static function Window (id : int, screenRect : Rect, func : GUI.WindowFunction, image : Texture, : ) : Rect
static function Window (id : int, screenRect : Rect, func : GUI.WindowFunction, content : GUIContent, : ) : Rect
static function Window (id : int, screenRect : Rect, func : GUI.WindowFunction, text : string, style : GUIStyle, : ) : Rect
static function Window (id : int, screenRect : Rect, func : GUI.WindowFunction, image : Texture, style : GUIStyle, : ) : Rect
static function Window (id : int, screenRect : Rect, func : GUI.WindowFunction, content : GUIContent, style : GUIStyle, : ) : Rect

Parameters参数

Returns

Rect - the rectangle the window is at. This can be in a different position and have a different size than the one you passed in.

返回Rect类型,该window所在的矩形。比你传入的一个,这个可以在一个不同的位置和有一个不同的大小。

Description描述

Make a popup window that layouts its contents automatically.

创建一个弹出窗口,它的内容是自动布局的。

Windows float above normal GUI controls, feature click-to-focus and can optionally be dragged around by the end user. Unlike other controls, you need to pass them a separate function for the GUI controls to put inside the window. Here is a small example to get you started:

这个窗口浮动在普通GUI控件之上,具有单击激活的特点并可选由终端用户拖动。不像其他控件,你需要为GUI控件传递单独的函数放置窗口中。这里是一个小的例子帮你入门:

GUILayout.Window 窗口

Window in the Game View.
在游戏视图中的窗口。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public Rect windowRect = new Rect(20, 20, 120, 50);
	void OnGUI() {
		windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window");
	}
	void DoMyWindow(int windowID) {
		if (GUILayout.Button("Hello World"))
			print("Got a click");

	}
}
var windowRect : Rect = Rect (20, 20, 120, 50);

function OnGUI () {
	// Register the window. Notice the 3rd parameter
	//注册窗口,注意第三个参数
	windowRect = GUILayout.Window (0, windowRect, DoMyWindow, "My Window");
}

// Make the contents of the window
//创建该窗口的内容
function DoMyWindow (windowID : int) {
	// This button will size to fit the window
	//这个按钮将适配该窗口
	if (GUILayout.Button ("Hello World"))
		print ("Got a click");
}

The screen rectangle you pass in to the function only acts as a guide. To Apply extra limits to the window, pass in some extra layout options. The ones applied here will override the size calculated. Here is a small example:

你传入函数的屏幕矩形,仅作为一个参考。为了对窗口使用额外的限制,传入一些额外的布局选项,有一个应用到这里,将重写计算大小。这里是一个小例子:

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public Rect windowRect = new Rect(20, 20, 120, 50);
	void OnGUI() {
		windowRect = GUILayout.Window(0, windowRect, DoMyWindow, "My Window", GUILayout.Width(100));
	}
	void DoMyWindow(int windowID) {
		if (GUILayout.Button("Please click me a lot"))
			print("Got a click");

	}
}
var windowRect : Rect = Rect (20, 20, 120, 50);

function OnGUI () {
	// Register the window. Here we instruct the layout system to
	// make the window 100 pixels wide no matter what.
	//注册窗口,这里我们指示布局系统无论如何使窗口为100像素宽。
	windowRect = GUILayout.Window (
	0, windowRect, DoMyWindow, "My Window", GUILayout.Width (100));
}

// Make the contents of the window
//创建窗口的内容
function DoMyWindow (windowID : int) {
	// This button is too large to fit the window
	//这个按钮比限制的窗口大
	// Normally, the window would have been expanded to fit the button, but due to
	// the GUILayout.Width call above the window will only ever be 100 pixels wide
	//通常,这个窗口将被扩展以便适应这个按钮。但是由于GUILayout.Width将只允许窗口为100像素宽
	if (GUILayout.Button ("Please click me a lot"))
		print ("Got a click");
}
Page last updated: 2011-6-14