GUI.DragWindow 拖动窗口

static function DragWindow (position : Rect) : void

Parameters参数

Returns

Rect - the rectangle the window is at.

返回 Rect类型,窗口所在的矩形。

Description描述

Make a window draggable.

创建一个可拖动窗口。

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

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

using UnityEngine;
using System.Collections;

public class example : 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));
	}
}
var windowRect : Rect = Rect (20, 20, 120, 50);

function OnGUI () {
	//注册一个窗口
	windowRect = GUI.Window (0, windowRect, DoMyWindow, "My Window");
}

//创建窗口内容
function DoMyWindow (windowID : int) {
	//创建一个10000x20像素很长的矩形
	//这样做可以你调整窗口大小而不用在修改这个值,20就是标题栏的高度,这个范围是可以拖动的
	GUI.DragWindow (Rect (0,0, 10000, 20));	
}

• static function DragWindow () : void

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.

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

另见: DragWindow, BringWindowToFront, BringWindowToBack

using UnityEngine;
using System.Collections;

public class example : 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();
	}
}
var windowRect : Rect = Rect (20, 20, 120, 50);

function OnGUI () {
	//注册一个窗口
	windowRect = GUI.Window (0, windowRect, DoMyWindow, "My 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 ();
}
最后修改:2011年1月14日 Friday 20:51

本脚本参考基于Unity 3.4.1f5

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