返回介绍

GUI.DragWindow 拖动窗口

发布于 2019-12-18 15:37:45 字数 3904 浏览 1189 评论 0 收藏 0

JavaScript => public static function DragWindow(position: Rect): void;
C# => public static void DragWindow(Rect position);

Parameters 参数

positionThe part of the window that can be dragged. This is clipped to the actual window.
能拖动窗口部分的位置,这是被修剪到实际窗口。

Description 描述

Make a window draggable.

创建一个可拖动窗口。

Insert a call to this function inside your window code to make a window draggable.

在你的窗口代码,插入调用到这个函数,来创建一个可拖动窗口。

JavaScript:

var windowRect : Rect = Rect (20, 20, 120, 50);
 
	function OnGUI () {
		// Register the window.
		windowRect = GUI.Window (0, windowRect, DoMyWindow, "My Window");
	}
 
	// Make the contents of the window
	function DoMyWindow (windowID : int) {
		// Make a very long rect that is 20 pixels tall. 
		// This will make the window be resizable by the top
		// title bar - no matter how wide it gets.
		GUI.DragWindow (Rect (0,0, 10000, 20));
	}

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) {
        GUI.DragWindow(new Rect(0, 0, 10000, 20));
    }
}

JavaScript => public static function DragWindow(): void;
C# => public static void DragWindow();

Description 描述

If you want to have the entire window background to act as a drag area, use the version of DragWindow that takes no parameters and put it at the end of the window function.

如果你想将完整的窗口背景作为拖动区域,使用DragWindow不带参数的版本,放在窗口函数的末尾。

This will mean that any other controls will get precedence and the dragging will only be activated if nothing else has mouse focus. See Also: DragWindow, BringWindowToFront, BringWindowToBack.

这将意味着,任何其他控件将会得到优先,拖动将仅在如果没有别的鼠标焦点被激活。请参考:DragWindow, BringWindowToFront, BringWindowToBack。

JavaScript:

	var windowRect : Rect = Rect (20, 20, 120, 50);
 
	function OnGUI () {
		windowRect = GUI.Window (0, windowRect, DoMyWindow, "My Window");
	}
 
	// Make the contents of the window
	function DoMyWindow (windowID : int) {
		GUI.Button (Rect (10,20,100,20), "Can't drag me");
		// Insert a huge dragging area at the end.
		// This gets clipped to the window (like all other controls) so you can never
		//  drag the window from outside it.
		GUI.DragWindow ();
	}

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) {
        GUI.Button(new Rect(10, 20, 100, 20), "Can't drag me");
        GUI.DragWindow();
    }
}

gui

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

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

发布评论

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