Unity3D---GUI

来源:互联网 发布:sql server 2008密钥 编辑:程序博客网 时间:2024/05/16 10:18
GUI

1、标签:

Label (position : Rect, text : string) : void
Label (position : Rect, image : Texture) : void
Label (position : Rect, content : GUIContent) : void
Label (position : Rect, text : string, style : GUIStyle) : void
Label (position : Rect, image : Texture, style : GUIStyle) : void
Label (position t, conte: Recnt : GUIContent, style : GUIStyle) : void
Rect:有四个参数x、y、wide、height
Text:显示在标签上的文本
Image:显示标签上的纹理
Style:使用样式

如:

public Texture2D img;
void OnGUI() {
GUI.Label(new Rect(10, 10, 100, 20), "Hello World!");
GUI.Label(new Rect(10,50,img.width,img.height),img);
}

2、盒子:

Box (position : Rect, text : string) : void
Box (position : Rect, image : Texture) : void
Box (position : Rect, content : GUIContent) : void
Box (position : Rect, text : string, style : GUIStyle) : void
Box (position : Rect, image : Texture, style : GUIStyle) : void
Box (position : Rect, content : GUIContent, style : GUIStyle) : void

如:

public Texture2D img;
void OnGUI() {
GUI.Box(new Rect(10, 10, 100, 20), "Hello World!");
GUI.Box(new Rect(10,50,img.width,img.height),img);
}

3、按钮

Button (position : Rect, text : String) : bool
Button (position : Rect, image : Texture) : bool
Button (position : Rect, content : GUIContent) : bool
Button (position : Rect, text : String, style : GUIStyle) : bool
Button (position : Rect, image : Texture, style : GUIStyle) : bool
Button (position : Rect, content : GUIContent, style : GUIStyle) : bool

如:

GUI.Button(new Rect(10, 80, 150, 20), new GUIContent("我有提示", "恭喜你中奖了!"));
// 在旁边的位置显示提示信息。
GUI.Label(new Rect(130, 40, 150, 40), GUI.tooltip);
//按钮上面有图片
GUI.Button(new Rect(10, 180, 150, 20), new GUIContent("我有提示", img));

4、重复按钮

RepeatButton (position : Rect, text : String) : bool
RepeatButton (position : Rect, image : Texture) : bool
RepeatButton (position : Rect, content : GUIContent) : bool
RepeatButton (position : Rect, text : String, style : GUIStyle) : bool
RepeatButton (position : Rect, image : Texture, style : GUIStyle) : bool
RepeatButton (position : Rect, content : GUIContent, style : GUIStyle) : bool

如:

GUI.RepeatButton(new Rect(10, 10, 100, 20), "Hello World!");
GUI.RepeatButton(new Rect(10, 50, img.width, img.height), img);
GUI.RepeatButton(new Rect(10, 80, 150, 20), new GUIContent("我有提示", "恭喜你中奖了!"));
// 在旁边的位置显示提示信息。
GUI.RepeatButton(new Rect(130, 40, 150, 40), GUI.tooltip);
GUI.RepeatButton(new Rect(10, 180, 150, 20), new GUIContent("我有提示", img));

5、文本:

TextField (position : Rect, text : String) : String
TextField (position : Rect, text : String, maxLength : int) : String
TextField (position : Rect, text : String, style : GUIStyle) : String
TextField (position : Rect, text : String, maxLength : int, style : GUIStyle) : String

如:

string str="Hello World";
str = GUI.TextField(new Rect(10, 10, 200, 20), str);
str = GUI.TextField(new Rect(10, 10, 200, 20), str, 25);

6、密码文本:

PasswordField (position : Rect, password : String, maskChar : char) : String
PasswordField (position : Rect, password : String, maskChar : char, maxLength : int) : String
PasswordField (position : Rect, password : String, maskChar : char, style : GUIStyle) : String
PasswordField (position : Rect, password : String, maskChar : char, maxLength : int, style : GUIStyle) : String

如:

string str= "请输入密码:";
str= GUI.PasswordField(new Rect(10, 10, 200, 20), str, "*"[0]);
str= GUI.PasswordField(new Rect(10, 10, 200, 20), str, "*"[0],10);或
str= GUI.PasswordField(new Rect(10, 10, 200, 20), str, ‘*’,10);

7、文本域:

TextArea (position : Rect, text : String) : String
TextArea (position : Rect, text : String, maxLength : int) : String
TextArea (position : Rect, text : String, style : GUIStyle) : String
TextArea (position : Rect, text : String, maxLength : int, style : GUIStyle) : String

如:

string str = "aaaa\nbbbb";
str = GUI.TextArea(new Rect(10, 10, 200, 100), str);
str = GUI.TextArea(new Rect(10, 10, 200, 100), str, 200);

8、Application事件

//跳转到登录视图
Application.LoadLevel("Login");
//跳转到本视图(游戏重新开始)
Application.LoadLevel(Application.loadedLevelName);
//退出游戏
Application.Quit();

9、字体设置

//设置字体大小
GUI.skin.label.fontSize=50;
//设置字体颜色
GUI.color = Color.red;
string aa = "我们都很好";


更多精彩请点击 http://www.gopedu.com/
0 0
原创粉丝点击