diff --git a/Runtime/MobileInputField.cs b/Runtime/MobileInputField.cs index b5cf747..c162cdf 100644 --- a/Runtime/MobileInputField.cs +++ b/Runtime/MobileInputField.cs @@ -6,6 +6,9 @@ using NiceJson; using UnityEngine.Events; +using UnityEngine.InputSystem; +using UnityEngine.InputSystem.EnhancedTouch; + namespace UMI { /// @@ -274,6 +277,7 @@ public enum ReturnKeyType { /// Constructor /// void Awake() { + //EnhancedTouchSupport.Enable(); _inputObject = GetComponent(); if ((object)_inputObject == null) { #if UMI_DEBUG @@ -410,6 +414,35 @@ IEnumerator InitProcess() { /// If changed - send to plugin /// It's need when app rotate on input field chage position /// + + +/* +void Update() { +#if UNITY_ANDROID && !UNITY_EDITOR + UpdateForceKeyeventForAndroid(); +#endif + + if (_inputObject != null && _isMobileInputCreated) { +#if !UNITY_EDITOR + var inputRect = _inputObjectText.rectTransform.rect; + + foreach (var touch in UnityEngine.InputSystem.EnhancedTouch.Touch.activeTouches) { + if (!inputRect.Contains(touch.screenPosition)) { +#if UMI_DEBUG + Debug.Log($"[UMI] manual hide control: {IsManualHideControl}"); +#endif + if (!IsManualHideControl) { + Hide(); + } + return; + } + } +#endif + SetRectNative(_inputObjectText.rectTransform); + } +} +*/ + void Update() { #if UNITY_ANDROID && !UNITY_EDITOR UpdateForceKeyeventForAndroid(); @@ -436,6 +469,7 @@ void Update() { } } + /// /// Prepare config /// @@ -808,36 +842,49 @@ public void SetVisible(bool isVisible) { } #if UNITY_ANDROID && !UNITY_EDITOR + + private void ForceSendKeydownAndroid(string key) + { + var data = new JsonObject + { + ["msg"] = ANDROID_KEY_DOWN, + ["key"] = key + }; + Execute(data); + } - /// - /// Send android button state - /// - /// Code - private void ForceSendKeydownAndroid(string key) { - var data = new JsonObject(); - data["msg"] = ANDROID_KEY_DOWN; - data["key"] = key; - Execute(data); - } - - /// - /// Keyboard handler - /// - private void UpdateForceKeyeventForAndroid() { - if (Input.anyKeyDown) { - if (Input.GetKeyDown(KeyCode.Backspace)) { - ForceSendKeydownAndroid("backspace"); - } else { - foreach (var c in Input.inputString) { - if (c == '\n') { - ForceSendKeydownAndroid("enter"); - } else { - ForceSendKeydownAndroid(Input.inputString); - } + /// + /// Keyboard handler + /// + private void UpdateForceKeyeventForAndroid() + { + var keyboard = Keyboard.current; + if (keyboard == null) return; + + // Check for any key press + if (keyboard.anyKey.wasPressedThisFrame) + { + if (keyboard.backspaceKey.wasPressedThisFrame) + { + ForceSendKeydownAndroid("backspace"); + } + else if (keyboard.enterKey.wasPressedThisFrame) + { + ForceSendKeydownAndroid("enter"); + } + else + { + foreach (var key in keyboard.allKeys) + { + if (key.wasPressedThisFrame) + { + ForceSendKeydownAndroid(key.displayName.ToLower()); + break; // Avoid sending multiple keys at once } } } } + } #endif }