查看: 1009|回复: 0
打印 上一主题 下一主题

[经验分享] Unity3D 学习从简单开始-GUI探索

[复制链接]

14

主题

1

听众

272

积分

设计实习生

Rank: 2

纳金币
35
精华
0
跳转到指定楼层
楼主
发表于 2017-2-23 11:15:23 |只看该作者 |倒序浏览
  今天为大家分享一下,如何快速认识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    

分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-4 01:00 , Processed in 0.086736 second(s), 30 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部