- 最后登录
- 2017-5-15
- 注册时间
- 2012-3-1
- 阅读权限
- 90
- 积分
- 32973
- 纳金币
- 32806
- 精华
- 12
|
移动窗体
//設定拖曳視窗大小
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));
}
|
|