unity game Developemnt in 24 hours 第13章 GUI
2014-06-04 09:58
344 查看
1. GUI是什么? Graphical User Interface ,图形化用户接口,也就是我们在界面上看到的操作界面,比如按钮button、文字说明,选项等等,他是2D的,目前unity3d只支持在代码中编写,没有编辑器。
注:建议在编写代码时吧此类GUI相关的写到一起统一管理。
2. 内置的GUI组件分为: label, box,toggle等
cs代码如下:
int someValue = 0;
bool toggleState = false;
int buttonInt = 0;
string[] list = {"Easy" , "Normal", "Hard"} ;
// string textString = "Enter text Here" ;
string textString = "" ;
string textString2 = "" ;
void OnGUI(){
// GUI.Label (new Rect ( Screen.width/2 , Screen.height/2 , 80, 20), "Hello World");
// GUI.Label (new Rect ( Screen.width/2 , Screen.height/2 , 100 , 50), "Hello World");
// GUI.Box (new Rect ( Screen.width/2 - 50 , 0 , 100 , 50), "Hello World");
toggleState = GUI.Toggle (new Rect ( 80, 0, 80, 30), toggleState , "My Toggle" ) ;
buttonInt = GUI.Toolbar (new Rect ( 200, 0, 200, 30), buttonInt, list);
if (GUI.Button (new Rect (Screen.width / 2 - 50, 0, 100, 50), "下一步")) {
print ("22222222222222222" ) ;
}
if (GUI.RepeatButton ( new Rect ( 0, 0, 40, 20), "+1")) {
someValue += 1 ;
print(someValue );
}
textString = GUI.TextField( new Rect ( 0, 30, 200, 30), textString );
textString2 = GUI.TextArea( new Rect ( 0, 80, 200, 100), textString2 );
vValue = GUI.VerticalSlider( new Rect ( 305, 150, 20, 150), vValue , 0, 100 );
hValue = GUI.HorizontalSlider( new Rect ( 300 , 130, 150, 20), hValue , 0, 100 );
}
float hValue = 0;
float vValue = 0 ;
3. 自定义GUI样式,cs代码如下:
public GUISkin skin ;
void OnGUI(){
GUI.skin = skin;
if ( GUI.Button (new Rect (5, 5, 200, 50), "Hello World") );
}
其中skin是在Asset中create的,可以再Inspector界面编辑属性
注:建议在编写代码时吧此类GUI相关的写到一起统一管理。
2. 内置的GUI组件分为: label, box,toggle等
cs代码如下:
int someValue = 0;
bool toggleState = false;
int buttonInt = 0;
string[] list = {"Easy" , "Normal", "Hard"} ;
// string textString = "Enter text Here" ;
string textString = "" ;
string textString2 = "" ;
void OnGUI(){
// GUI.Label (new Rect ( Screen.width/2 , Screen.height/2 , 80, 20), "Hello World");
// GUI.Label (new Rect ( Screen.width/2 , Screen.height/2 , 100 , 50), "Hello World");
// GUI.Box (new Rect ( Screen.width/2 - 50 , 0 , 100 , 50), "Hello World");
toggleState = GUI.Toggle (new Rect ( 80, 0, 80, 30), toggleState , "My Toggle" ) ;
buttonInt = GUI.Toolbar (new Rect ( 200, 0, 200, 30), buttonInt, list);
if (GUI.Button (new Rect (Screen.width / 2 - 50, 0, 100, 50), "下一步")) {
print ("22222222222222222" ) ;
}
if (GUI.RepeatButton ( new Rect ( 0, 0, 40, 20), "+1")) {
someValue += 1 ;
print(someValue );
}
textString = GUI.TextField( new Rect ( 0, 30, 200, 30), textString );
textString2 = GUI.TextArea( new Rect ( 0, 80, 200, 100), textString2 );
vValue = GUI.VerticalSlider( new Rect ( 305, 150, 20, 150), vValue , 0, 100 );
hValue = GUI.HorizontalSlider( new Rect ( 300 , 130, 150, 20), hValue , 0, 100 );
}
float hValue = 0;
float vValue = 0 ;
3. 自定义GUI样式,cs代码如下:
public GUISkin skin ;
void OnGUI(){
GUI.skin = skin;
if ( GUI.Button (new Rect (5, 5, 200, 50), "Hello World") );
}
其中skin是在Asset中create的,可以再Inspector界面编辑属性
相关文章推荐
- unity game Developemnt in 24 hours 第23章 Polish and Deploy 游戏发布
- unity game Developemnt in 24 hours 第1章 untiy
- unity game Developemnt in 24 hours 第20章 Audio 声音
- unity game Developemnt in 24 hours 第2章 Game Objects
- Sams teach yourself game programming in 24 hours
- Making a mobile game in 24 hours
- Unity SLua+FairyGUI
- 【Unity】模仿GUILayout.SelectionGird绘制一组互斥的按钮
- Adding iPhone Touch Scrolling to a UnityGUI ScrollView
- 自己开发一个 unity gui sgui
- Sams Teach Yourself Microsoft Office Access 2003 in 24 Hours
- 电子书下载:Teach Yourself Microsoft Dynamics CRM 2011 in 24 Hours
- 【Unity3D】Unity GUI的选择与评价
- Unity3D的GUI插件(UIToolkit,GUIX)在Unity的社区里发现一个不错的UI插件----UIToolkit.
- unity 3d GUI.Toolbar以及GUI.Toggle
- UnityGUI系统之Canvas
- Unity GUI选择与评价
- Unity 查看所有GUI默认样式
- unity各种 GUI
- 【构造】 Codeforces 468A 24 Game