返回介绍

GUI.Window 窗口

发布于 2019-12-18 15:37:46 字数 14052 浏览 982 评论 0 收藏 0

JavaScript => public static function Window(id: int, clientRect: Rect, func: GUI.WindowFunction, text: string): Rect;
JavaScript => public static function Window(id: int, clientRect: Rect, func: GUI.WindowFunction, image: Texture): Rect;
JavaScript => public static function Window(id: int, clientRect: Rect, func: GUI.WindowFunction, content: GUIContent): Rect;
JavaScript => public static function Window(id: int, clientRect: Rect, func: GUI.WindowFunction, text: string, style: GUIStyle): Rect;
JavaScript => public static function Window(id: int, clientRect: Rect, func: GUI.WindowFunction, image: Texture, style: GUIStyle): Rect;
JavaScript => public static function Window(id: int, clientRect: Rect, func: GUI.WindowFunction, title: GUIContent, style: GUIStyle): Rect;

C# => public static Rect Window(int id, Rect clientRect, GUI.WindowFunction func, string text);
C# => public static Rect Window(int id, Rect clientRect, GUI.WindowFunction func, Texture image);
C# => public static Rect Window(int id, Rect clientRect, GUI.WindowFunction func, GUIContent content);
C# => public static Rect Window(int id, Rect clientRect, GUI.WindowFunction func, string text, GUIStyle style);
C# => public static Rect Window(int id, Rect clientRect, GUI.WindowFunction func, Texture image, GUIStyle style);
C# => public static Rect Window(int id, Rect clientRect, GUI.WindowFunction func, GUIContent title, GUIStyle style);

Parameters 参数

StyleAn optional style to use for the window. If left out, the window style from the current GUISkin is used.
可选择的用于窗口的格式。如果丢失,那么从当前GUISkin的窗口格式被使用。
idID number for the window (can be any value as long as it is unique).
用于每个窗口的唯一ID。这是你用于接口的ID。
clientRectOnscreen rectangle denoting the window's position and size.
用于窗口组在屏幕上的矩形位置。
funcScript function to display the window's contents.\\在窗口中创建GUI的函数,这个函数必须获得一个参数-用于当前创建GUI的窗口ID。
textText to render inside the window.
用于窗口的标题文本显示。
imageImage to render inside the window.
在标题栏显示图片纹理。
contentGUIContent to render inside the window.
用于窗口的文本,图片和提示。
styleStyle information for the window.
用户窗口的可选样式,如果不设置,窗口样式应用当前的GUISkin皮肤。
titleText displayed in the window's title bar.
在窗口标题栏中显示的标题。

Returns

Rect Onscreen rectangle denoting the window's position and size.
返回 Rect类型,窗口所在的矩形。

Description 描述

Make a popup window.

创建一个弹出窗口。

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 that renders the GUI controls inside the window.

窗口浮动在普通GUI控件之上,点选焦点和能被终端用户随意拖动的特点,不像其他的控件,你需要为GUI控件传递她们一个单独的函数放进窗口。

Note: If you are using GUILayout to place your components inside the window, you should use GUILayout.Window. Also, if MonoBehaviour.useGUILayout is set to false then a call to GUI.Window will not have any effect, even though it is not a GUILayout function.

注意,如果你使用GUILayout在窗口中放你的组件,你需要使用GUILayout.Window。当然,如果MonoBehaviour.useGUILayout被设置为false那么调用GUI.Window将不会有任何作用,尽管他不是GUILayout函数。

JavaScript:

var windowRect : Rect = Rect (20, 20, 120, 50);
 
	function OnGUI () {
		// Register the window. Notice the 3rd parameter 
		windowRect = GUI.Window (0, windowRect, DoMyWindow, "My Window");
	}
 
	// Make the contents of the window
	function DoMyWindow (windowID : int) {
		if (GUI.Button (Rect (10,20,100,20), "Hello World"))
			print ("Got a click");
	}

You can use the same function to create multiple windows. Just make sure that each window has its own ID. Example:

你可以使用一样的函数来创建多个窗口,要确定每一个窗口有自己的ID。

JavaScript:

var windowRect0 : Rect = Rect (20, 20, 120, 50);
	var windowRect1 : Rect = Rect (20, 100, 120, 50);
 
	function OnGUI () {
		// Register the window. We create two windows that use the same function
		// Notice that their IDs differ
		windowRect0 = GUI.Window (0, windowRect0, DoMyWindow, "My Window");
		windowRect1 = GUI.Window (1, windowRect1, DoMyWindow, "My Window");
	}
 
	// Make the contents of the window
	function DoMyWindow (windowID : int) {
		if (GUI.Button (Rect (10,20,100,20), "Hello World"))
			print ("Got a click in window " + windowID);
		// Make the windows be draggable.
		GUI.DragWindow (Rect (0,0,10000,10000));
	}

To stop showing a window, simply stop calling GUI.Window from inside your main OnGUI function:

停止显示一个窗口,从你的主DoGUI函数中简单停止调用GUI.Window。

JavaScript:

// boolean variable to decide whether to show the window or not.
	// Change this from the in-game GUI, scripting, the inspector or anywhere else to
	// decide whether the window is visible
	var doWindow0 : boolean = true;
 
	// Make the contents of the window.
	function DoWindow0 (windowID : int) {
		GUI.Button (Rect (10,30, 80,20), "Click Me!");
	}
 
	function OnGUI () {
		// Make a toggle button for hiding and showing the window
		doWindow0 = GUI.Toggle (Rect (10,10,100,20), doWindow0, "Window 0");
 
		// Make sure we only call GUI.Window if doWindow0 is true.
		if (doWindow0)
			GUI.Window (0, Rect (110,10,200,60), DoWindow0, "Basic Window");
	}

To make a window that gets its size from automatic GUI layouting, use GUILayout.Window. Call Ordering Windows need to be drawn back-to-front; windows on top of other windows need to be drawn later than the ones below them. This means that you can not count on your DoWindow functions to be called in any particular order. In order for this to work seamlessly, the following values are stored when you create your window (using the Window function), and retrieved when your DoWindow gets called: GUI.skin, GUI.enabled, GUI.color, GUI.backgroundColor, GUI.contentColor, GUI.matrix.

要创建一个自动GUI布局的窗口,使用GUILayout.Window。窗口需要从后向前绘制。在其他窗口上面的窗口需要比他们下面的窗口晚绘制。你不能指望在你的Dowindow函数中调用任意特定排序。为了使整个工作无缝,当你创建窗口时下面的值被储存(使用窗口函数),并且当你的DoWindow被GUI.skin, GUI.enabled, GUI.color, GUI.backgroundColor, GUI.contentColor, GUI.matrix调用时,重新取回。

JavaScript:

	var windowRect0 : Rect = Rect (20, 20, 120, 50);
	var windowRect1 : Rect = Rect (20, 100, 120, 50);
 
	function OnGUI () {
		// Here we make 2 windows. We set the GUI.color value to something before each.
		GUI.color = Color.red;		
		windowRect0 = GUI.Window (0, windowRect0, DoMyWindow, "Red Window");
 
		GUI.color = Color.green;		
		windowRect1 = GUI.Window (1, windowRect1, DoMyWindow, "Green Window");
	}
 
	// Make the contents of the window.
	// The value of GUI.color is set to what it was when the window
	// was created in the code above.
	function DoMyWindow (windowID : int) {
		if (GUI.Button (Rect (10,20,100,20), "Hello World"))
			print ("Got a click in window with color " + GUI.color);
		// Make the windows be draggable.
		GUI.DragWindow (Rect (0,0,10000,10000));
	}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    public Rect windowRect = new Rect(20, 20, 120, 50);
    void OnGUI() {
        windowRect = GUI.Window(0, windowRect, DoMyWindow, "My Window");
    }
    void DoMyWindow(int windowID) {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
            print("Got a click");
 
    }
}

You can use the same function to create multiple windows. Just make sure that each window has its own ID. Example:

你可以使用一样的函数来创建多个窗口,要确定每一个窗口有自己的ID。

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    public Rect windowRect0 = new Rect(20, 20, 120, 50);
    public Rect windowRect1 = new Rect(20, 100, 120, 50);
    void OnGUI() {
        windowRect0 = GUI.Window(0, windowRect0, DoMyWindow, "My Window");
        windowRect1 = GUI.Window(1, windowRect1, DoMyWindow, "My Window");
    }
    void DoMyWindow(int windowID) {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
            print("Got a click in window " + windowID);
 
        GUI.DragWindow(new Rect(0, 0, 10000, 10000));
    }
}

To stop showing a window, simply stop calling GUI.Window from inside your main OnGUI function:

停止显示一个窗口,从你的主DoGUI函数中简单停止调用GUI.Window。

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    public bool doWindow0 = true;
    void DoWindow0(int windowID) {
        GUI.Button(new Rect(10, 30, 80, 20), "Click Me!");
    }
    void OnGUI() {
        doWindow0 = GUI.Toggle(new Rect(10, 10, 100, 20), doWindow0, "Window 0");
        if (doWindow0)
            GUI.Window(0, new Rect(110, 10, 200, 60), DoWindow0, "Basic Window");
 
    }
}

To make a window that gets its size from automatic GUI layouting, use GUILayout.Window. Call Ordering Windows need to be drawn back-to-front; windows on top of other windows need to be drawn later than the ones below them. This means that you can not count on your DoWindow functions to be called in any particular order. In order for this to work seamlessly, the following values are stored when you create your window (using the Window function), and retrieved when your DoWindow gets called: GUI.skin, GUI.enabled, GUI.color, GUI.backgroundColor, GUI.contentColor, GUI.matrix.

要创建一个自动GUI布局的窗口,使用GUILayout.Window。窗口需要从后向前绘制。在其他窗口上面的窗口需要比他们下面的窗口晚绘制。你不能指望在你的Dowindow函数中调用任意特定排序。为了使整个工作无缝,当你创建窗口时下面的值被储存(使用窗口函数),并且当你的DoWindow被GUI.skin, GUI.enabled, GUI.color, GUI.backgroundColor, GUI.contentColor, GUI.matrix调用时,重新取回。

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    public Rect windowRect0 = new Rect(20, 20, 120, 50);
    public Rect windowRect1 = new Rect(20, 100, 120, 50);
    void OnGUI() {
        GUI.color = Color.red;
        windowRect0 = GUI.Window(0, windowRect0, DoMyWindow, "Red Window");
        GUI.color = Color.green;
        windowRect1 = GUI.Window(1, windowRect1, DoMyWindow, "Green Window");
    }
    void DoMyWindow(int windowID) {
        if (GUI.Button(new Rect(10, 20, 100, 20), "Hello World"))
            print("Got a click in window with color " + GUI.color);
 
        GUI.DragWindow(new Rect(0, 0, 10000, 10000));
    }
}

gui

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

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

发布评论

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