เริ่มกันเลยครับ
1. ให้ทำการเปิด Script DataPanelEditor.cs
2. การเขียน Form เราจะเขียนใน Function OnGUI() นะครับ ซึ่งจะใช้ GUILayout เป็นหลัก
3. ขั้นตอนแรกเราจะทำการสร้าง Form ในแนวนอนนะครับ โดยใช้ GUILayout.BeginHorizontal(); และ GUILayout.EndHorizontal(); (ถ้าไม่มีการ set Horizontal Unity ก็จะ default เป็น Vertical)
string username = "";
string password = "";
void OnGUI()
{
GUILayout.BeginHorizontal();
// สร้าง Label และกำหนดความกว้าง 100
GUILayout.Label("Username : ", GUILayout.Width(100));
// เป็นการสร้าง Input Text และนำค่าใส่ตัวแปร name
username = GUILayout.TextField(username, GUILayout.MaxWidth(150));
GUILayout.Label("Password : ", GUILayout.Width(100));
password = GUILayout.PasswordField(password, '*', 20, GUILayout.MaxWidth(150));
GUILayout.EndHorizontal();
// สร้างปุ่ม Save
if (GUILayout.Button("Login"))
{
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
{
EditorUtility.DisplayDialog("Error", "Please insert username and password.", "OK");
return;
}
string result = string.Format("Username is {0}", username );
// แสดง Dialog
EditorUtility.DisplayDialog("Your Name", result, "OK");
// สามารถ เช็ค Data หรือ Save Data ได้นะครับไม่ว่าจะเป็น File หรือ ScriptableObject
}
}
หวังว่าจะมีประโบชน์ไม่มากก็น้อยนะครับ
NO GAME NO DREAM!!!!