纳金网
标题: Unity3D 学习从简单开始-GUI探索 [打印本页]
作者: Cici_coach 时间: 2017-2-23 11:15
标题: Unity3D 学习从简单开始-GUI探索
今天为大家分享一下,如何快速认识unity3d 的原生GUI,其实说到GUI,它是Unity中一个强大的脚本API,可以快速的创建的简单的菜单UI,所以我们有必要了解一下它是如何使用的。然而文章极其的简单,相信一看便知其意。学习交流:575561285.
GUI 官方文档:http://www.ceeger.com/Script/GUI/GUI.html
1.新建一个unity3d 测试项目,新建GUITest.cs组件,考虑把GUI常用的函数做一个列举。
2.GUITest.cs 组件代码如下:
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class GUITest : MonoBehaviour {
- public string passwordToEdit = "My Password";
- public string stringToEdit = "Hello World\nI've got 2 lines...";
- public string stringToEditField = "Hello World";
- private bool toggleTxt = false;
- public int toolbarInt = 0;
- public string[] toolbarStrings = new string[] {"Toolbar1", "Toolbar2", "Toolbar3"};
- public float vSbarValue;
- public float vSliderValue = 0.0F;
- void OnGUI ()
- {
- //1.Label :显示文本内容
- GUI.Label (new Rect (100,0,400,50), "This is the text string for a Label Control");
- //2.Button :显示一个菜单按钮
- GUI.Button (new Rect (100,70, 200, 50), "This is a Button");
- //3.Box :绘制纹理
- GUI.Box(new Rect(0,0,Screen.width,Screen.height),"This is a title");
- //4.PasswordField :显示密码框
- passwordToEdit = GUI.PasswordField(new Rect(100, 140, 200, 20), passwordToEdit, "*"[0], 25);
- //5.RepeatButton :重复按钮
- GUI.RepeatButton(new Rect(100, 210, 200, 50), "This is a RepeatButton");
- //6.TextArea :显示多行文本
- stringToEdit = GUI.TextArea(new Rect(100, 280, 200, 60), stringToEdit, 200);
- //7.TextField :显示文本字段
- stringToEdit = GUI.TextField (new Rect(100, 350, 200, 20), stringToEditField, 25);
- //8.Toggle :开关按钮
- toggleTxt = GUI.Toggle(new Rect(100, 420, 100, 30), toggleTxt, "A Toggle text");
- //9.Toolbar :工具栏
- toolbarInt = GUI.Toolbar(new Rect(100, 490, 250, 30), toolbarInt, toolbarStrings);
- //10.tooltip :工具提示
- GUI.Button(new Rect(100, 560, 100, 20), new GUIContent("Click me", "This is the tooltip"));
- GUI.Label(new Rect(300, 560, 100, 40), GUI.tooltip);
- //11.VerticalScrollbar :垂直滚动条
- vSbarValue = GUI.VerticalScrollbar (new Rect(100, 630, 100, 60), vSbarValue, 1.0F, 10.0F, 0.0F);
- //12.VerticalSlider :垂直滑动条
- vSliderValue = GUI.VerticalSlider (new Rect(400, 630, 100, 60), vSliderValue, 10.0F, 0.0F);
- }
- }
复制代码
3.最后运行看整体效果哈!
欢迎光临 纳金网 (http://rs.narkii.com/club/) |
Powered by Discuz! X2.5 |