GUI控件:
1.在Start中初始化,在OnGUI中调整。
2.公有变量才会出现在Inspector面板。
3.GUI控件的初始化和处理在OnGUI内完成。
4.JavaScript的中文为UTF-8编码可显示,CSharp的中文为UTF-16编码可显示。
基本信息:
屏幕宽高:Screen.width Screen.height
图片宽高:img.width img.height
一 标签Label
GUI.Label(Rect(x,y,width,height),<Str or Texture, such as Texture2D>);
二 按钮Button
var buttonTexture : Texture2D;
GUI.Button(Rect(x,y,width,height),buttonTexture);
设置文字颜色:GUI.color = Color.green;
设置背景颜色:GUI.backgroundColor = Color.red;
三 输入框TextField
message = GUI.TextField(Rect(x,y,width,height),message,size);
message = GUI.PasswordField(Rect(x,y,width,height),message,"*"[0],size);
返回值类型为String.
四 复选框与标签页selectToggle and Toolbar
var barResource : String[] = ["bar1","bar2","bar3",...];
var select : int;
var state : boolean;
select = GUI.Toolbar(Rect,default,barResource);//第二个参数为默认在第几个标签上,后面为名字列表,
有几个元素就有几个标签。
获取标签页:select = GUI.Toolbar(...);
获取复选框:state = GUI.Toggle(Rect,state,
Unity3D学习笔记(一)GUI控件的调用
最新推荐文章于 2020-03-24 10:52:39 发布
