一、
首先要说明使用GUI组件,需在void OnGUi(){ }函数中声明和操作GUI组件;
二、组件的创建
文本框:GUI.Label(new Rect(ScrenceX,ScrenceY,Width,High),"txt");//new Rect中前两个参数表示组件在屏幕中的位置,以左上角为零点;后两个参数为组件大小的宽和高," "括起来的为组件中的txt内容;
按钮: if (GUI.Button(new Rect(100, 130, 60, 40), "按钮1"))
{
txt = "被点了";//通过按钮控制文本输出
}
三、输入框:
uname= GUI.TextField(new Rect(100, 170, 60, 30), uname );
四、密码框:
pwd= GUI.PasswordField(new Rect(100, 200, 60, 30), pwd, '*');
应用:做一个注册窗口
void OnGUI()
{
//------------------------------登录界面GUI-------------------------
GUI.Label(new Rect(100,20,100,20),txtuname);//使用label显示输入框中输入的内容
GUI.Label(new Rect(100,40,100,20),txtpwd);
GUI.Label(new Rect(100,80,60,20),"user:");
GUI.Label(new Rect(100,110,60,20),"Password:");
uname= GUI.TextField(new Rect (170,80,200,20),uname);
pwd= GUI.PasswordField(new Rect(170,110,200,20),pwd,'*');
if( GUI.Button(new Rect(150,160,60,30),"登录"))
{
}
if( GUI.Button(new Rect(250,160,60,30),"注册")){
winflag=1;
txtuname=uname;
txtpwd=pwd;
}
if(winflag==1)
{
winRect=GUI.Window(0,winRect,winFun,"注册");
}
}
//------------------------------注册界面GUI-------------------------
void winFun(int winId)
{
GUI.DragWindow(new Rect(0,0,40,30));//限制窗体响应鼠标的范围,可拖拽窗体区域
if( GUI.Button(new Rect(468,0,30,30),"X")){
winflag=0;
}
scrollFlag=GUI.BeginScrollView(new Rect(10,30,480,260),scrollFlag,new Rect(0,0,800,600));//滚动条制作
//GUI.VerticalScrollbar(new Rect(480,10,400,200),scrollFlag,1,0,100);
//GUI.Box(new Rect(0,0,400,300),"box");多行文本框
GUI.Label(new Rect(100,80,60,20),"user:");
GUI.Label(new Rect(100,110,60,20),"Password:");
if( GUI.Button(new Rect(250,160,60,30),"sign")){
}
uname1= GUI.TextField(new Rect (170,80,200,20),uname1);
pwd1= GUI.PasswordField(new Rect(170,110,200,20),pwd1,'*');
//if(GUI.Toggle(new Rect(160,180,20,20),tog,"nan")){
//tog=true;
//}
tog=GUI.Toggle(new Rect(160,150,60,60),tog,"男");//单选框
GUI.EndScrollView();
//结束被开始的滚动视图,注意BeginScrollView和
EndScrollView它们是成对出现的。
}
更多精彩内容请到:
http://www.gopedu.com/
}