zoukankan      html  css  js  c++  java
  • Unity3D: 获取输入/控件焦点

    简单来讲,就是

    1. 用GUI.SetNextControlName为该行代码的下一句控件设置名字
    2. GUI.FocusControl来把焦点设置到某控件上,这里将用到上一步设置的名字

    用GUI.GetNameOfFocusedControl来获得焦点控件的名字。

    示例代码1:

    GUI.SetNextControlName("Text1");
    text1 = GUILayout.TextField(text1);
    GUI.SetNextControlName("Text2");
    text2 = GUILayout.TextField(text2);
    if (GUI.GetNameOfFocusedControl() == string.Empty) {
        // Set focus to control Text1.
        GUI.FocusControl("Text1");
    }

    官方示例代码:

    using UnityEngine;
    using System.Collections;
    
    public class example : MonoBehaviour {
        public string username = "username";
        public string pwd = "a pwd";
        void OnGUI() {
            GUI.SetNextControlName("MyTextField");
            // This control will be named MyTextField.
            username = GUI.TextField(new Rect(10, 10, 100, 20), username);
            pwd = GUI.TextField(new Rect(10, 40, 100, 20), pwd);
            if (GUI.Button(new Rect(10, 70, 80, 20), "Move Focus"))
                GUI.FocusControl("MyTextField");
            
        }
    }
  • 相关阅读:
    k8s-istio记录
    k8s
    单词 -(动物)
    RxJs
    .netcore 3.1 unbuntu
    单词规整
    AutoMapper
    时间
    ye
    特殊权限
  • 原文地址:https://www.cnblogs.com/codingmylife/p/3110334.html
Copyright © 2011-2022 走看看