Skip to content

Instantly share code, notes, and snippets.

@rutcreate
Created July 25, 2015 01:56
Show Gist options
  • Save rutcreate/92e3c9e68a319c0fe029 to your computer and use it in GitHub Desktop.
Save rutcreate/92e3c9e68a319c0fe029 to your computer and use it in GitHub Desktop.
Unity3D: GUI control name explanation.
using UnityEngine;
using UnityEditor;
using System.Collections;
public class GUIControlEditorWindow : EditorWindow {
[MenuItem("Window/GUIControl Test")]
public static void OpenGUIControlEditorWindow() {
EditorWindow.GetWindow<GUIControlEditorWindow>();
}
private string username;
private string password;
private string fullName;
private string address;
private string noFocusName;
private string focus;
private void OnGUI() {
EditorGUILayout.BeginVertical("Box");
GUI.SetNextControlName("Username");
username = EditorGUILayout.TextField("Username", username);
GUI.SetNextControlName("Password");
password = EditorGUILayout.TextField("Password", password);
GUI.SetNextControlName("Full name");
fullName = EditorGUILayout.TextField("Full name", fullName);
EditorGUILayout.LabelField("Address");
GUI.SetNextControlName("Address");
address = EditorGUILayout.TextArea(address, GUILayout.Height(50f));
noFocusName = EditorGUILayout.TextField("No focus name", noFocusName);
EditorGUILayout.EndVertical();
// Set focus control.
EditorGUILayout.BeginVertical("Box");
focus = EditorGUILayout.TextField("Name", focus);
if (GUILayout.Button("Focus")) {
GUI.FocusControl(focus);
}
EditorGUILayout.EndVertical();
// Focus control debug.
EditorGUILayout.BeginVertical("Box");
EditorGUILayout.LabelField("Focus on: " + GUI.GetNameOfFocusedControl());
EditorGUILayout.EndVertical();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment