Unity3D学习笔记————GUI
程序员文章站
2022-03-26 14:40:49
...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GUItest : MonoBehaviour
{
string str1;
bool isClick;
bool isClick1;
int showFrame;
string uname;
string ukey;
private void Start()
{
str1 = null;
isClick = false;
isClick1 = false;
showFrame = 0;
uname = null;
ukey = "";
}
private void OnGUI()
{
#region GUI控件测试
//文本框Label
GUILayout.Label("欢迎进入!");
str1 = GUILayout.TextField(str1,GUILayout.Width(100));
//点击按钮
if(GUILayout.Button("点击",GUILayout.Width(100),GUILayout.Height(100))){
isClick = true;
Debug.Log(1);
}
if(isClick)
GUILayout.Label("按钮点击");
//Tab页
GUILayout.Toolbar(3, new string[] { "装备", "经验", "队友" });
//复选框
if(GUILayout.Toggle(isClick1, "静音")){
isClick1 = !isClick;
}
if (isClick1)
{
GUILayout.Label("静音");
}
//页面布局
//开启一行
GUILayout.BeginHorizontal();
//之间内容都在一行
//结束一行
GUILayout.EndHorizontal();
//开启一列
GUILayout.BeginVertical();
//之间内容都在一列
//结束一列
GUILayout.EndVertical();
//闪烁按钮
showFrame++;
if(showFrame>=50){
GUILayout.Button("闪烁按钮");
if(showFrame>=100){
showFrame = 0;
}
}
#endregion
#region 登录
uname = GUILayout.TextField(uname, GUILayout.Width(100));
//ukey = GUILayout.TextField(ukey, GUILayout.Width(100));
ukey = GUILayout.PasswordField(ukey, '*', GUILayout.Width(100));
//按钮
if (GUILayout.Button("Login", GUILayout.Width(100)))
{
if (uname == "ly" && ukey == "123")
{
isClick = true;
}
else
isClick = false;
}
if (isClick)
GUILayout.Label("登陆成功!");
else
GUILayout.Label("登录失败!");
#endregion
#region Buton 与RepeatButton对比
if (GUILayout.Button("一次点击")) {
this.gameObject.transform.Translate(Vector3.right);
}
if(GUILayout.RepeatButton("点击",GUILayout.Width(100))){
this.gameObject.transform.Translate(Vector3.right*0.01f);
}
#endregion
}
}