- 最后登录
- 2019-12-2
- 注册时间
- 2012-8-25
- 阅读权限
- 90
- 积分
- 34660
- 纳金币
- 38268
- 精华
- 111
|
移动窗体
//設定拖曳視窗大小
var windowRect : Rect = Rect (20, 20, 120, 50);
//限制可移動範圍
var constrain : Rect;
//滑鼠座標
private var e : Event;
function OnGUI () {
//取得滑鼠座標
e = Event.current;
//顯示範圍用,可有可無
GUI.Box(constrain, "Drag Here");
windowRect = GUI.Window (0, windowRect, DoMyWindow, "My Window");
}
function DoMyWindow (windowID : int) {
//限制可移動範圍
if(e.mousePosition.x > constrain.x && e.mousePosition.x < (constrain.width + constrain.x) && e.mousePosition.y > constrain.y && e.mousePosition.y < (constrain.height + constrain.y)){
GUI.DragWindow (Rect (0,0, 10000, 20));
}
}
模态窗口
// Draws 2 overlapped windows and when clicked on 1 window's button
// Brings the other window to the front.
private var windowRect : = [url=]Rect (20, 20, 120, 50);
private var windowRect2 : = [url=]Rect (80, 20, 120, 50);
function OnGUI () {
windowRect = [url=]GUI.Window[/url] (0, windowRect, DoMyFirstWindow, "First");
windowRect2 = [url=]GUI.Window[/url] (1, windowRect2, DoMySecondWindow, "Second" );
}
function DoMyFirstWindow (windowID : int) {
if ( ([url=]Rect (10,20,100,20), "Bring to front"))
[url=]GUI.BringWindowToFront[/url](1); //Bring the 2nd window to front
([url=]Rect (0,0, 10000, 20));
}
function DoMySecondWindow (windowID : int) {
if ( ([url=]Rect (10,20,100,20), "Bring to front"))
[url=]GUI.BringWindowToFront[/url](0); //Bring the 1rst window to front
([url=]Rect (0,0, 10000, 20));
}
|
|