Day05之GUI

来源:互联网 发布:叶紫涵网络直播 编辑:程序博客网 时间:2024/06/10 15:42


Demo1

using UnityEngine;
using System.Collections;

public class Demo1 : MonoBehaviour {

    public string _strText="nihao";
    public string _strP="";
    public int _IntSelectIndex;

    public bool _boolCheck1;
    public bool _boolCheck2;

    public float _value;
    public float _max=100.0f;
    public float _min=0.0f;
    // Use this for initialization
    void Start () {
    
    }
    
    // Update is called once per frame
    void Update () {
    
    }

    void OnGUI(){
    
        print (Screen.width+" : "+Screen.height);
        GUI.Label (new Rect (20,20,100,40),"Nihao");
        GUI.Label (new Rect (Screen.width / 2, Screen.height / 2, 100, 40), "Buhao");
        _strText = GUI.TextField (new Rect (100,50,100,30),_strText);//文本框

        _strP = GUI.PasswordField (new Rect (0,50,100,30),_strP,'*');

        if(GUI.Button(new Rect (0,150,50,30),"按钮")){
            print ("Ni an l an niu");
        }

        _IntSelectIndex = GUI.Toolbar (new Rect (0,200,200,30),_IntSelectIndex,new string[]{"Duty","Equip","People"});

        _boolCheck1 = GUI.Toggle (new Rect (0,250,100,150),_boolCheck1,"toggle");

        //_boolCheck2 = GUI.Toggle (new Rect (0,300,100,150),_boolCheck2,"toggle2");

        _value = GUI.HorizontalSlider (new Rect (250,300,200,50),_value,_min,_max);
        print (_value);

    }
}

Demo2

using UnityEngine;
using System.Collections;

public class Demo2 : MonoBehaviour {

    // Use this for initialization
    void Start () {
    
    }
    
    // Update is called once per frame
    void Update () {
    
    }

    void OnGUI(){
        GUILayout.BeginArea (new Rect (100,200,300,100));
        GUILayout.Button ("sure");
        GUILayout.Label ("I am lable");
        GUILayout.Label ("Hello world");
        GUILayout.Label ("Hello world");
        GUILayout.EndArea ();
    }
}

Demo3

using UnityEngine;
using System.Collections;

public class Demo3 : MonoBehaviour {

    public bool _boolDisplay;
    public bool _winDisplay;

    // Use this for initialization
    void Start () {
    
    }
    
    // Update is called once per frame
    void Update () {
    
    }

    void OnGUI(){
    
        if(GUILayout.Button("Show")){
            GUILayout.Label ("I can not be show");
            print ("jia you a ,zhen kou qi");
        }

        if(GUILayout.Button("xianshi")){
            _boolDisplay = true;
        }
        if(_boolDisplay){
            GUILayout.Label ("ok I am show");
        }

        if(GUILayout.Button("Show Window")){
            _winDisplay = true;
        }
        if(_winDisplay){
            GUILayout.Window (0,new Rect (100,100,200,200),AddWindow,"MyWindow");
        }
    }

    void AddWindow(int winId){
        if(GUILayout.Button("Exit")){
            _winDisplay = false;
        }
    }
}

Demo4


using UnityEngine;
using System.Collections;

public class Demo4 : MonoBehaviour {

    public Texture2D Txt2D_Coin;
    private Texture2D _Txt2D_bird;

    // Use this for initialization
    void Start () {
    
        //_Txt2D_bird = (Texture2D)Resources.Load ("1");

        _Txt2D_bird= Resources.Load<Texture2D> ("1");


    }
    
    // Update is called once per frame
    void Update () {
    
    }

    void OnGUI(){
    
        GUI.DrawTexture (new Rect (0,0,_Txt2D_bird.width,_Txt2D_bird.height),_Txt2D_bird);

        GUI.DrawTexture (new Rect (0,0,Txt2D_Coin.width/2,Txt2D_Coin.height/2 ),Txt2D_Coin);
    }
}

Demo5


using UnityEngine;
using System.Collections;

public class Demo5 : MonoBehaviour {

    public GUISkin mySkin;


    private string[] infos = new string[5];
    Vector2 scrollPosition;
    // Use this for initialization
    void Start () {
    
        infos [0] = "jian che may be yi is very difficult,bu yao qing yu de da kai xin men";
        infos [1] = "but wo want to fight,nu li cai neng zhan de gen gao chu";
        infos [2] = "yanwei i an is a man,wai mian de shi jie hai zai deng ni";
        infos [3] = "ye xi zhe ge keneng hui cheng wei kou hao ,yan wei you yi ge gen yi zhi zai deng ni";
        infos [4] = "dan shi jue ding shi zai zj de shou shang,gao shang zhi dian cai neng wangchuang yi que";
    }
    
    // Update is called once per frame
    void Update () {
    
        GameObject.Find ("Cube").GetComponent<Transform> ().Translate (new Vector3 (0,0,Time.deltaTime));
        print (Time.deltaTime);
    }
    void OnGUI(){
    
//        if(GUI.Button(new Rect (100,100,100,100),"",mySkin.GetStyle("button1"))){
//            print ("Nihao");
//            Application.LoadLevel (1);
//
//        }

//        for(int i=0;i<5;i++){
//            for(int j=0;j<5;j++){
//                if(GUI.Button(new Rect (100*j,100*i,80,80),"",mySkin.GetStyle("button1"))){
//                    ButtonClick (
//                    );
//                }
//            }
//        }


//        GUI.skin = mySkin;
//        scrollPosition = GUI.BeginScrollView (new Rect (10,10,400,400),scrollPosition,new Rect (10,10,700,700),true,true);
//        GUI.Label (new Rect (10, 10, 770, 40), infos [0]);
//        GUI.Label (new Rect (10, 50, 770, 40), infos [1]);
//        GUI.Label (new Rect (10, 90, 770, 40), infos [2]);
//        GUI.Label (new Rect (10, 130, 770, 40), infos [3]);
//        GUI.Label (new Rect (10, 170, 770, 40), infos [4]);
//        GUI.EndScrollView ();


        if(GUI.Button(new Rect (140,0,100,50),"zhandint")){
            Time.timeScale = 0;
        }
        if(GUI.Button(new Rect(280,0,100,50),"jixi")){
            Time.timeScale = 1;
        }
    }
    void ButtonClick(int id){
        print (id);
    }
}

0 0