[Unity] Unity3D 学习从简单开始-GUI探索

查看:1294 |回复:30 | 2017-2-23 10:49:37

您需要 登录 才可以下载或查看,没有账号?注册

x
   今天为大家分享一下,如何快速认识unity3d 的原生GUI,其实说到GUI,它是Unity中一个强大的脚本API,可以快速的创建的简单的菜单UI,所以我们有必要了解一下它是如何使用的。然而文章极其的简单,相信一看便知其意。
   欢迎加我的学习交流群:575561285.
  GUI 官方文档:http://www.ceeger.com/Script/GUI/GUI.html
   1.新建一个unity3d 测试项目,新建GUITest.cs组件,考虑把GUI常用的函数做一个列举。
                  1.png
   2.GUITest.cs 组件代码如下:
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;

  4. public class GUITest : MonoBehaviour {


  5.         public string passwordToEdit = "My Password";
  6.         public string stringToEdit = "Hello World\nI've got 2 lines...";
  7.         public string stringToEditField = "Hello World";
  8.         private bool toggleTxt = false;

  9.         public int toolbarInt = 0;
  10.         public string[] toolbarStrings = new string[] {"Toolbar1", "Toolbar2", "Toolbar3"};

  11.         public float vSbarValue;
  12.         public float vSliderValue = 0.0F;

  13.         void OnGUI ()
  14.         {
  15.                 //1.Label :显示文本内容
  16.                 GUI.Label (new Rect (100,0,400,50), "This is the text string for a Label Control");
  17.                 //2.Button :显示一个菜单按钮
  18.                 GUI.Button (new Rect (100,70, 200, 50), "This is a Button");
  19.                 //3.Box :绘制纹理
  20.                 GUI.Box(new Rect(0,0,Screen.width,Screen.height),"This is a title");
  21.                 //4.PasswordField :显示密码框
  22.                 passwordToEdit = GUI.PasswordField(new Rect(100, 140, 200, 20), passwordToEdit, "*"[0], 25);
  23.                 //5.RepeatButton :重复按钮
  24.                 GUI.RepeatButton(new Rect(100, 210, 200, 50), "This is a RepeatButton");
  25.                 //6.TextArea :显示多行文本
  26.                 stringToEdit = GUI.TextArea(new Rect(100, 280, 200, 60), stringToEdit, 200);
  27.                 //7.TextField :显示文本字段
  28.                 stringToEdit = GUI.TextField (new Rect(100, 350, 200, 20), stringToEditField, 25);
  29.                 //8.Toggle :开关按钮
  30.                 toggleTxt = GUI.Toggle(new Rect(100, 420, 100, 30), toggleTxt, "A Toggle text");
  31.                 //9.Toolbar :工具栏
  32.                 toolbarInt = GUI.Toolbar(new Rect(100, 490, 250, 30), toolbarInt, toolbarStrings);
  33.                 //10.tooltip :工具提示
  34.                 GUI.Button(new Rect(100, 560, 100, 20), new GUIContent("Click me", "This is the tooltip"));
  35.                 GUI.Label(new Rect(300, 560, 100, 40), GUI.tooltip);
  36.                 //11.VerticalScrollbar :垂直滚动条
  37.                 vSbarValue = GUI.VerticalScrollbar (new Rect(100, 630, 100, 60), vSbarValue, 1.0F, 10.0F, 0.0F);
  38.                 //12.VerticalSlider :垂直滑动条
  39.                 vSliderValue = GUI.VerticalSlider (new Rect(400, 630, 100, 60), vSliderValue, 10.0F, 0.0F);

  40.         }
  41. }
点击此处复制文本

   3.最后运行看整体效果哈!
    3.png
   

评分

参与人数 2元素币 +18 活跃度 +15 展开 理由
小小橘子 + 3 + 15 我现在很少用OnGUI了~大部分都是UGUI了
狼之独步 + 15 学习快乐~

查看全部评分

2017-2-23 10:49:37  
 赞 赞 0

使用道具 登录

30个回答,把该问题分享到群,邀请大神一起回答。
2#
经常普及小知识,辛苦啦
回复 收起回复
2017-2-23 12:45:42   回复
 赞 赞 0

使用道具 登录

3#
6666666666666666666666666666666666666666
回复 收起回复
2017-9-16 16:32:47   回复
 赞 赞 0

使用道具 登录

4#
涨知识了
回复 收起回复
2018-11-9 09:00:32   回复
 赞 赞 0

使用道具 登录

5#
元素帖子强,满满正能量!
回复 收起回复
2018-11-9 09:06:17   回复
 赞 赞 0

使用道具 登录

6#

难得一见的绝世好贴!
回复 收起回复
2018-11-9 11:33:24   回复
 赞 赞 0

使用道具 登录

7#
谢谢分享!!
回复 收起回复
2018-11-10 00:53:10   回复
 赞 赞 0

使用道具 登录

8#

想要成大触,天天上元素!
回复 收起回复
2018-11-11 11:02:25   回复
 赞 赞 0

使用道具 登录

9#
想要成大触,天天上元素!
回复 收起回复
2018-11-11 11:07:03   回复
 赞 赞 0

使用道具 登录

10#
666
回复 收起回复
2018-11-12 08:49:34   回复
 赞 赞 0

使用道具 登录

11#
回复 收起回复
2018-11-22 09:05:23   回复
 赞 赞 0

使用道具 登录

12#
想要成大触,天天上元素!
回复 收起回复
2018-11-22 09:09:04   回复
 赞 赞 0

使用道具 登录

13#
哎呀,不错哦
回复 收起回复
2018-11-23 10:01:06   回复
 赞 赞 0

使用道具 登录

14#
内容很丰富
回复 收起回复
2018-11-25 12:08:56   回复
 赞 赞 0

使用道具 登录

15#
路过看看 感谢分享
回复 收起回复
2018-11-25 23:39:41   回复
 赞 赞 0

使用道具 登录

16#
路过看看 感谢分享
回复 收起回复
2018-11-25 23:39:44   回复
 赞 赞 0

使用道具 登录

17#
不错的资源,谢谢分享
回复 收起回复
2018-11-26 09:37:58   回复
 赞 赞 0

使用道具 登录

18#
66
回复 收起回复
2018-11-26 10:24:49   回复
 赞 赞 0

使用道具 登录

19#
元素大法好
回复 收起回复
2018-11-30 14:07:15   回复
 赞 赞 0

使用道具 登录

20#
微元素官方群,等级最低的头衔
回复 收起回复
2018-11-30 19:36:50   回复
 赞 赞 0

使用道具 登录

CG 游戏行业专业问题

Unity3D技术手机游戏引擎手游引擎
12下一页
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表