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


    复合控件极其使用,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。

  • 相关阅读:
    css(上)
    前端基础
    并发编程,python的进程,与线程
    网络编程 套接字socket TCP UDP
    python 类的内置函数2
    python3大特征之多态
    python 类(object)的内置函数
    类 与 继承
    类 与 面向对象
    OOP >>> 封装
  • 原文地址:https://www.cnblogs.com/liuruitao/p/4251577.html
Copyright © 2020-2023  润新知