Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
GUI.GetNameOfFocusedControl 获取有焦点被命名控件的名字
# [GUI](GUI.html "Go to GUI scripting documentation").*GetNameOfFocusedControl* 获取有焦点被命名控件的名字 static function *GetNameOfFocusedControl* () : [String](../String/String.html) *Description* 描述 Get the name of named control that has focus. 获取有焦点被命名控件的名字 Control names are set up by using [SetNextControlName](GUI.SetNextControlName.html). 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](GUI.SetNextControlName.html) 设置,当被命名控件有焦点,这个函数将返回他的名字,如果没有控件获得焦点或有焦点控件没有名字将返回空字符串。 GetNameOfFocusedControl works well when you make a login box. GetNameOfFocusedControl 可以用于创建注册框方面。 * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { public string login = "username"; public string login2 = "no action here"; void OnGUI() { GUI.SetNextControlName("user"); login = GUI.TextField(new Rect(10, 10, 130, 20), login); login2 = GUI.TextField(new 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"); } } ``` ``` 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](GUI.SetNextControlName.html), [FocusControl](GUI.FocusControl.html).
da
2022年5月23日 13:46
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码