unity之GUI基础
来源:互联网 发布:php autoload用法 编辑:程序博客网 时间:2024/05/17 04:45
欢迎来到unity学习、unity培训、unity企业培训教育专区,这里有很多U3D资源、U3D培训视频,我们致力于打造业内unity3d培训、学习第一品牌。
今天学习了新的内容:GUI
GUI使用OnGUI()调用,OnGUI每帧调用一次。
下面讲一下OnGUI中常用到的的几个控件。
1.Lable 文本
Label (position : Rect, text : string) : void //添加文字
Label (position : Rect, image : Texture) : void //添加图片
例:
public Texture img;
void OnGUI()
{
GUI.Label(new Rect(10,10,100,20),"Hello Word" );
GUI.Label(new Rect(10,40,img.width,img.height), img);
}
2.Box盒子边框
Box的特点为会有一圈边框。
Box (position : Rect, text : string) : void //添加文字
Box (position : Rect, image : Texture) : void //添加图片
例:
public Texture img;
void OnGUI()
{
GUI.Box(new Rect(10, 10, 100, 20), "Hello Word");
GUI.Box(new Rect(10, 40, img.width, img.height), img);
}
3.Button按钮框
Button中如果鼠标选中会有一个按钮被选中的效果,可以有点击效果提示
Button (position : Rect, text : String) : bool //返回值为Bool类型
Button (position : Rect, image : Texture) : bool
例:
void OnGUI()
{
GUI.Button(new Rect(10, 10, 100, 20), new GUIContent("Hello Word","GG") );
GUI.Label (new Rect (130,30,50,20),GUI.tooltip );
}
4.RepeatButton双击按钮
在RepeatButton中如果鼠标选中会有双击效果,与button一样也会有点击提示。
RepeatButton (position : Rect, text : String) : bool //返回值为bool类型
RepeatButton (position : Rect, image : Texture) : bool
public Texture img;
void OnGUI()
{
GUI.RepeatButton(new Rect(10, 10, 100, 20), "Hello World!");
GUI.RepeatButton(new Rect(10, 50, img.width, img.height), img);
}
5.TextField输入框
使用TextField可以输入字符。
TextField (position : Rect, text : String) : String //返回值为string 类型
TextField (position : Rect, text : String, maxLength : int) : String //输入字符数量有限制
例:
string stc = "Hello Word";
void OnGUI()
{
stc = GUI.TextField(new Rect(10,10,100,20),stc );
stc = GUI.TextField(new Rect (10,10,100,50),stc,10);//限制只能输入十个字符
}
6.PasswordField密码框
可以使输入的字符显示为隐藏
"*"[0]等价于'*' 单引号内的*可以更改为其他字符
PasswordField (position : Rect, password : String, maskChar : char) : String
例:
string stc = "Hello Word";
void OnGUI()
{
stc = GUI.PasswordField(new Rect(10, 10, 100, 20), stc, '*');
}
7.TextArea多行输入
可以输入多行
TextArea (position : Rect, text : String) : String // 输入为string类型
TextArea (position : Rect, text : String, maxLength : int) : String //限制输入字符数量
例:
string stc = "Hello Word";
void OnGUI()
{
stc = GUI.TextArea(new Rect (10,10,200,200),stc);
stc = GUI.TextArea(new Rect (10,10,200,200),stc,200);//只能输入200个字符
}
- unity之GUI基础
- Unity之GUI基础
- unity之GUI基础
- Unity学习之GUI基础
- unity之GUI基础(二)
- unity学习之GUI基础2
- 01.Unity GUI基础
- C#编写Unity基础GUI之按钮控件
- Unity学习之GUI
- Unity学习之GUI
- unity学习之GUI
- Unity之GUI复习
- Unity项目之GUI注册
- java基础之GUI
- java基础之GUI
- Java基础之GUI
- java基础之GUI
- unity基础开发----GUI实用代码
- greensock缓动类包之TweenLite
- Altium Designer 6.9(学习二)
- iOS开发的22个巧技
- 推荐算法入门
- 程序员创业,千万别创成外包
- unity之GUI基础
- 《数据结构》实验三: 栈和队列实验
- 从HttpServletRequest request, 中读取数据流中的内容
- ipad 桌面图标异常
- lua部分函数说明
- Altium Designer 6.9(学习三)
- oracle数据库number()里面2个数字的含义
- Java基础----多线程程序解决
- 《程序员 你伤不起》读后感(二)