首页 > 代码库 > unity3d常用控件

unity3d常用控件

直接上代码,就能看懂了。

private string txt1;
private string pwd1;
private int tool1;
private bool isMuted;
private string msgBody;

// Use this for initialization
void Start () {
    txt1 = "";
    pwd1 = "";
    tool1 = 0;
    isMuted = true;
    msgBody = "";
}
//GUI内容显示
void OnGUI(){
    //文本框
    txt1=GUILayout.TextField (txt1,GUILayout.Width(100));
    //密码框,用*来代替原字符
    pwd1 = GUILayout.PasswordField (pwd1, *, GUILayout.Width (100));
    //按钮,如果按下会返回true
    if (GUILayout.Button ("showLog")) {
        Debug.Log (1);
    }
    //Tab页,tool1用于接收按下的是哪一个tab,默认从0开始
    tool1 = GUILayout.Toolbar (tool1, new string[]{ "a", "b", "c" });
    Debug.Log (tool1);
    //复选框,可以选中或不选中
    if(GUILayout.Toggle(isMuted,"静音")){
        isMuted = false;
    }else{
        isMuted = true;
    }
    //多行文本
    msgBody=GUILayout.TextArea(msgBody,GUILayout.Width(100),GUILayout.Height(50));
}

 

unity3d常用控件