EditorWindow.BeginWindows 开始窗口

function BeginWindows () : void

Description描述

Mark the beginning area of all popup windows.

标记所有弹出窗口的开始区域。

GUI.Window behaves somewhat differently in the editor than inside your games. In games, GUI.Window pops up a window on your screen. In the editor, GUI.Window shows a subwindow inside one of your editor windows. Begin/EndWindows is used to determine where these can go. You need to have all calls to GUI.Window or GUILayout.Window inside a BeginWindows / EndWindows pair. Like this:

GUI.Window的行为在编辑器中比在游戏中有所不同。在游戏中,GUI.Window在屏幕上弹出一个窗口;在编辑器中,GUI.Window在编辑器窗口中显示一个子窗口。Begin/EndWindows用于定义窗口。你需要让所有调用的GUI.WindowGUILayout.WindowBeginWindows / EndWindows对内。

Simple editor Window with a window and a button inside.

带有一个窗口和一个按钮的简单编辑器窗口。

class GUIWindowDemo extends EditorWindow {
	// The position of the window
	//窗口的位置
	var windowRect = Rect (100,100,200,200);

	// Main GUI Function //主GUI函数
	function OnGUI () {
		// Begin Window
		BeginWindows ();

		// All GUI.Window or GUILayout.Window must come inside here
		//所有GUI.Window 或 GUILayout.Window 必须在这里面
		windowRect = GUILayout.Window (1, windowRect, DoWindow, "Hi There");

		// Collect all the windows between the two.
		//在这两者之间搜集所有窗口
		EndWindows ();
	}

	// The window function. This works just like ingame GUI.Window
	//窗口函数,这就像游戏内的GUI.Window
	function DoWindow () {
		GUILayout.Button ("Hi");
		GUI.DragWindow ();
	}

	// Add menu item to show this demo.
	//添加菜单项来显示这个演示
	@MenuItem ("Test/GUIWindow Demo")
	static function Init () {
		EditorWindow.GetWindow (GUIWindowDemo);
	}
}

The placement of the BeginWindows / EndWindows pair determines where popup windows will appear; all windows are clipped to the clipping area defined by GUI.BeginGroup or GUI.BeginScrollview. A small example of that

BeginWindows / EndWindows对的放置决定弹出窗口的显示。所有窗口都放到GUI.BeginGroupGUI.BeginScrollview中定义。一个简单的例子:

EditorWindow.BeginWindows 开始窗口

Simple editor window with a window and a button inside using scroll bars.

带有一个窗口和一个按钮,使用滚动条的简单编辑器窗口。

class GUIWindowDemo2 extends EditorWindow {
	// The position of the window
	//窗口的位置
	var windowRect = Rect (100,100,200,200);

	// Scroll position 滚动位置
	var scrollPos = Vector2.zero;

	function OnGUI () {
		// Set up a scroll view 设置滚动视图
		scrollPos = GUI.BeginScrollView (
			new Rect (0, 0, position.width, position.height),
			scrollPos,
			new Rect (0, 0, 1000, 1000)
		);

		// Same code as before - make a window. Only now, it's INSIDE the scrollview
		//创建一个窗口,仅限在,在滚动视图中
		BeginWindows ();
		windowRect = GUILayout.Window (1, windowRect, DoWindow, "Hi There");
		EndWindows ();

		// Close the scroll view 关闭滚动视图
		GUI.EndScrollView ();
	}

	function DoWindow () {
		GUILayout.Button ("Hi");
		GUI.DragWindow ();
	}

	@MenuItem ("Test/GUIWindow Demo 2")
	static function Init () {
		EditorWindow.GetWindow (GUIWindowDemo2);
	}
}
最后修改:2011年5月29日 Sunday 12:33

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。