Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 72 additions & 25 deletions Runtime/MobileInputField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
using NiceJson;
using UnityEngine.Events;

using UnityEngine.InputSystem;
using UnityEngine.InputSystem.EnhancedTouch;

namespace UMI {

/// <summary>
Expand Down Expand Up @@ -274,6 +277,7 @@ public enum ReturnKeyType {
/// Constructor
/// </summary>
void Awake() {
//EnhancedTouchSupport.Enable();
_inputObject = GetComponent<TMP_InputField>();
if ((object)_inputObject == null) {
#if UMI_DEBUG
Expand Down Expand Up @@ -410,6 +414,35 @@ IEnumerator InitProcess() {
/// If changed - send to plugin
/// It's need when app rotate on input field chage position
/// </summary>


/*
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();
Expand All @@ -436,6 +469,7 @@ void Update() {
}
}


/// <summary>
/// Prepare config
/// </summary>
Expand Down Expand Up @@ -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);
}

/// <summary>
/// Send android button state
/// </summary>
/// <param name="key">Code</param>
private void ForceSendKeydownAndroid(string key) {
var data = new JsonObject();
data["msg"] = ANDROID_KEY_DOWN;
data["key"] = key;
Execute(data);
}

/// <summary>
/// Keyboard handler
/// </summary>
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);
}
/// <summary>
/// Keyboard handler
/// </summary>
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

}
Expand Down