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.最后运行看整体效果哈!


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值