using UnityEngine; using UnityEngine.EventSystems; using TMPro; /// /// True while the user is editing a focused on-screen text field (e.g. the paint HUD's /// "save as" name input). Global gameplay/dev hotkeys consult this so typing a name like /// "Checkers" doesn't also fire single-key shortcuts (C = cycle pose, K = shutdown, /// the mode-switch key, Ctrl+Z = undo, ...). /// public static class TypingGuard { // Consulted several times per frame by the hotkey readers; the GetComponent lookups are cached // per selected GameObject (a selection change refreshes them). private static GameObject _cachedGo; private static TMP_InputField _cachedTmp; private static UnityEngine.UI.InputField _cachedLegacy; /// A text input field is currently focused and capturing keystrokes. public static bool IsTyping { get { var es = EventSystem.current; if (!es) return false; var go = es.currentSelectedGameObject; if (!go) return false; if (go != _cachedGo) { _cachedGo = go; _cachedTmp = go.GetComponent(); _cachedLegacy = _cachedTmp ? null : go.GetComponent(); } if (_cachedTmp) return _cachedTmp.isFocused; return _cachedLegacy && _cachedLegacy.isFocused; } } }