纳金网

标题: 移动窗体与模态窗体的脚本 [打印本页]

作者: 狂风大尉    时间: 2014-6-23 01:38
标题: 移动窗体与模态窗体的脚本
移动窗体

//設定拖曳視窗大小

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));

}


作者: hyui    时间: 2014-6-23 02:34
Thank you for sharing your knowledge!
作者: Kadina    时间: 2014-6-23 06:36
Thank you for sharing.
作者: jacob    时间: 2014-6-23 09:14
Thank you for sharing.
作者: texfill    时间: 2014-6-23 09:25
Thank you for sharing.
作者: jacob    时间: 2014-6-23 09:39

Thank you for sharing.
作者: shenyg77    时间: 2014-6-23 11:34
谢谢神奇的分享




欢迎光临 纳金网 (http://wwww.narkii.com/club/) Powered by Discuz! X2.5