GUI.GetNameOfFocusedControl 获取有焦点被命名控件的名字

static function GetNameOfFocusedControl () : String

Description描述

Get the name of named control that has focus.
获取有焦点被命名控件的名字

Control names are set up by using SetNextControlName. When a named control has focus, this function will return its name. If no control has focus or the focused control has no name set returns empty string.

控件名字由SetNextControlName设置,当被命名控件有焦点,这个函数将返回他的名字,如果没有控件获得焦点或有焦点控件没有名字将返回空字符串。

GetNameOfFocusedControl works well when you make a login box.

GetNameOfFocusedControl可以用于创建注册框方面。

var login : String = "username";
var login2 : String = "no action here";

function OnGUI () {
	GUI.SetNextControlName ("user");
	login = GUI.TextField (Rect (10,10,130,20), login);

	login2 = GUI.TextField (Rect (10,40,130,20), login2);
	if (Event.current.Equals (Event.KeyboardEvent ("return")) &&
		GUI.GetNameOfFocusedControl () == "user") {
		Debug.Log("Login");
	}

	if (GUI.Button(new Rect (150,10,50,20), "Login"))
		Debug.Log("Login");
}
参考: SetNextControlName, FocusControl.
最后修改:2011年6月15日 Wednesday 10:50

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。