我有两个统一的 TMP_InputField。一旦第一个有输入,我试图自动关注并激活另一个。我尝试了以下方法,但由于某些原因,它对我不起作用。
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UnityEngine.EventSystems;
public class FocusBox : MonoBehaviour
{
public TMP_InputField b1;
public TMP_InputField b2;
// Update is called once per frame
private void Update()
{
if (b1.isFocused)
{
if (b1.text.Length > 0)
{
b2.Select();
b1.DeactivateInputField();
}
}
Debug.Log("is b1 focused after : " + b1.isFocused);
}
}
不太确定“有输入”到底是什么意思。
但是,我认为您可以在
OnValueChanged
上使用TMP_InputField
事件。通过 Inspector 分配回调或以编程方式覆盖它。每次您的输入更改时,都会触发您的回调。