没有废话直接给代码
public static bool IsTypeing {
get {
var g = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject;
if (g) {
var input = g.GetComponent<UnityEngine.UI.InputField>();
return input && input.isFocused;
} else {
return false;
}
}
}
上述代码可以比较准确的判断出用户是否在打字,配合Input.anyKeyDown,效率更好一些。