FocusControl, GetNameOfFocusedControl, SetNextControlName
说明 | 将焦点移至某个控件上/获取焦点控件的名字/设置下一个控件的名字 |
---|
用法
public static void FocusControl(string name);
public static string GetNameOfFocusedControl();
public static void SetNextControlName(string name);
其中 FocusControl
的参数来源一般都是由 SetNextControlName
设置的控件名称。
示例
private void OnSceneGUI () {
Handles.BeginGUI ();
GUI.SetNextControlName ("Control 1");
GUILayout.TextField ("Control 1");
GUI.SetNextControlName ("Control 2");
GUILayout.TextField ("Control 2");
GUI.SetNextControlName ("Control 3");
GUILayout.TextField ("Control 3");
if (GUILayout.Button("Focus on control 1")) {
GUI.FocusControl ("Control 1");
Debug.Log (GUI.GetNameOfFocusedControl ());
}
if (GUILayout.Button ("Focus on control 2")) {
GUI.FocusControl ("Control 2");
Debug.Log (GUI.GetNameOfFocusedControl ());
}
if (GUILayout.Button ("Focus on control 3")) {
GUI.FocusControl ("Control 3");
Debug.Log (GUI.GetNameOfFocusedControl ());
}
Handles.EndGUI ();
}