码迷,mamicode.com
首页 > 编程语言 > 详细

从零开始学习UNITY3D(GUI篇 2)

时间:2015-01-27 00:10:09      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:

复合控件极其使用,toolbar,selectgrid

先看效果图:

技术分享

 

toolbar可以看作是一个button按钮的集合,一次只能点击一个按钮,

selectgrid又可以堪称是一个toolbar的集合。

代码如下:

using UnityEngine;
using System.Collections;

public class GUI2 : MonoBehaviour {
	int toolbarInt=0;//代表默认第n-1个按钮是激活的
	string[] toolbarstring={"工具","窗体","帮助"};//按钮名称个数和集合
	int selectgrid=0;
	string[] selectgridsring = {"grid 1","grid 2","grid 3","grid 4","grid 5"};
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	void OnGUI()
	{
		toolbarInt = GUI.Toolbar (new Rect (0, 0, 220, 40), toolbarInt, toolbarstring);

		selectgrid = GUI.SelectionGrid (new Rect (150, 60, 250, 80), selectgrid, selectgridsring, 2);//2列数,unity可自动缩放
		//检测控件是否发生了改变
		if (GUI.changed) {
			print("某些控件发生了改变");		
			//具体控件点击的改变
			if(toolbarInt==1)
			{
				print("toolbar1被点击了");

			}
		}
	}
}

 注释也比较全,具体不懂的到时候可以自行查API。

 

从零开始学习UNITY3D(GUI篇 2)

标签:

原文地址:http://www.cnblogs.com/liuruitao/p/4251577.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!