GUILayout实现自动布局
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestOnGUI : MonoBehaviour
{
void OnGUI()
{
GUI.Button(new Rect(25, 25, 100, 30),"我是个名字很长的按钮!");//固定布局
GUILayout.Button("我是个名字很长的按钮!");//自动布局
}
}
BeginArea/EndArea
设置区域
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestOnGUI : MonoBehaviour
{
void OnGUI()
{
GUILayout.BeginArea(new Rect(Screen.width/2-50,Screen.height/2-50,300,300));
GUILayout.Button("我是个名字很长的按钮!");
GUILayout.EndArea();
}
}
PasswordField
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestOnGUI : MonoBehaviour
{
public string password = "my password";
void OnGUI()
{
password = GUILayout.PasswordField(password,"*"[0],25);
}
}