01.Unity GUI基础
2015-01-30 15:15
274 查看
using UnityEngine; using System.Collections; public class GUI : MonoBehaviour { private string strl; private string pwd; private int selectedToolBarld; private bool isMuted; private string msgBody; private float value; private Rect windowRect; private bool showWindow; // Use this for initialization void Start() { //Debug.Log("from start");//start方法只执行一次 //start方法中一般都是写一些初始化的东西 strl = ""; pwd = ""; //记得初始化 不然会出现Object reference not set to an instance of an object selectedToolBarld = 0; isMuted = false; msgBody = "这里是多行文本框,你点个回车试试"; value = 0f; showWindow = false; windowRect = new Rect(300, 300, 100, 50); } // Update is called once per frame void Update() { //Debug.Log("from update");//update方法每一帧执行一次 } void OnGUI() { //文本域 GUILayout.Label("文本域"); //开启一个横向排列区域 GUILayout.BeginHorizontal(); GUILayout.Label("用户名:"); //文本框 //文本框这样直接写是不会出现东西的 //帧:每一帧都会擦除上一帧绘制的内容,并将内容重新绘制 //GUILayout.TextField("文本框"); strl = GUILayout.TextField(strl,GUILayout.Width(100)); //结束一个横向排列区域 GUILayout.EndHorizontal(); //开启一个横向排列区域 GUILayout.BeginHorizontal(); GUILayout.Label("密码:"); //密码框 pwd = GUILayout.PasswordField(pwd,'*',GUILayout.Width(100)); //结束一个横向排列区域 GUILayout.EndHorizontal(); //按钮 GUILayout.Button("我是按钮", GUILayout.Width(100)); //Tab页 selectedToolBarld = GUILayout.Toolbar(selectedToolBarld, new string[] { "装备","经验","队友"}); switch (selectedToolBarld) { case 0: showLabel(selectedToolBarld);break; case 1: showLabel(selectedToolBarld); break; case 2: showLabel(selectedToolBarld); break; case 3: showLabel(selectedToolBarld); break; default: break; } //复选框 isMuted = GUILayout.Toggle(isMuted, "静音"); //多行文本框 msgBody = GUILayout.TextArea(msgBody); //滑动条 //开启一个横向排列区域 GUILayout.BeginHorizontal(); GUILayout.Label("垂直滑动条"+value); value = GUILayout.VerticalSlider(value, 0f, 100f); value = GUILayout.VerticalScrollbar(value, 10f, 800f, 1f); //结束一个横向排列区域 GUILayout.EndHorizontal(); //绘制窗口 if (GUILayout.Button("绘制窗口")) { showWindow = true; } if (showWindow) { windowRect = GUILayout.Window(1, windowRect, AddWindow, "设备");//所有关于GUI绘制的代码,都要直接或间接的写到OnGUI方法中 } } private void AddWindow(int id) { //id表示窗口的编号,可以让一个脚本中弹出多个窗口,这些窗口可以共用一个回调函数 if (id == 1) { if (GUILayout.Button("选择武器,关闭窗口")) { showWindow = false;//关闭,其实就是不再绘制 } } //GUI.DragWindow();//new Rect(0,0,1000,1000) } private void showLabel(int selectedToolBarld) { GUILayout.Label("我是按钮" + selectedToolBarld, GUILayout.Width(100)); } }
相关文章推荐
- unity基础开发--学习EZGUI教程
- C#编写Unity基础GUI之按钮控件
- Unity菜鸟起飞01 -- 基础知识
- Unity编辑器拓展【Unity GUI基础】
- Unity GUI基础知识。。。。。
- [UnityShaderCookbook 读书笔记] [01] Unity Shader 基础
- 【Unity3D基础教程】给初学者看的Unity教程(六):理解Unity的新GUI系统(UGUI)
- C#编写Unity基础GUI之控件-2
- unity之GUI基础
- C#编写Unity基础GUI之动态窗口
- UnityGUI 基础
- unity之GUI基础
- unity基础开发----GUI实用代码
- C#编写Unity基础GUI之按钮控件GUILayout控件
- Unity_NGUI基础01_039
- Lesson01_Unity基础介绍_part01工具与界面
- unity之GUI基础(二)
- Unity学习之GUI基础
- C#编写Unity基础GUI之复合控件
- unity基础开发--学习EZGUI教程