06-29-2018 05:55 PM
09-25-2018 12:34 AM
09-29-2018 04:51 AM
11-21-2018 09:51 AM
11-27-2018 10:48 AM
01-25-2019 02:50 AM
02-01-2019 08:34 PM
02-14-2019 08:49 AM
yunhan0 said:
I solved this issue by writing a class inherits from the input field. So remove the default InputField component and attach the MobileInput. Don't forget to assign some properties such as TextComponent and Placeholder inside the new MobileInput Component.using UnityEngine;
using UnityEngine.UI;
public class MobileInput : InputField
{
protected override void Start()
{
keyboardType = (TouchScreenKeyboardType)(-1);
base.Start();
}
}
02-21-2019 03:12 AM
04-08-2019 05:26 AM
using System.Reflection;There are obvious flaws in this approach - its not really reliable to expect this to work with other versions of Unity other than the version I'm using - 2018.2.X. Thankfully the Unity UI is open source so using the links included in the comments above you could convert this to another version without too much hassle. I hope this helps some others too and maybe unity could implement a fix too. I will point them to this implementation however and who knows, we could see a fix.
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class GoInputField : InputField {
private void ActivateInputFieldInternal() {
if (EventSystem.current == null)
return;
if (EventSystem.current.currentSelectedGameObject != gameObject)
EventSystem.current.SetSelectedGameObject(gameObject);
if (TouchScreenKeyboard.isSupported) {
if (GetBaseInput().touchSupported) {
TouchScreenKeyboard.hideInput = shouldHideMobileInput;
}
// Here is where the touchscreen keyboard is opened - we exclude
// the calls to TouchScreenKeyboard.Open()
// https://bitbucket.org/Unity-Technologies/ui/src/9f418c4767c47d0c71f1727eb42a9a9024e9ecc0/UnityEngine...
MoveTextEnd(false);
} else {
GetBaseInput().imeCompositionMode = IMECompositionMode.On;
OnFocus();
}
SetField("m_AllowInput", true);
SetField("m_OriginalText", text);
SetField("m_WasCanceled", false);
CallMethod("SetCaretVisible");
UpdateLabel();
}
protected override void LateUpdate() {
bool _m_ShouldActivateNextUpdate = GetField("m_ShouldActivateNextUpdate");
if (_m_ShouldActivateNextUpdate) {
if (!isFocused) {
ActivateInputFieldInternal();
SetField("m_ShouldActivateNextUpdate", false);
return;
}
SetField("m_ShouldActivateNextUpdate", false);
}
// Here this method usually handles all the TouchScreenKeyboard checks and
// deselets the InputField if the keyboard is not visible - lets not do that.
// https://bitbucket.org/Unity-Technologies/ui/src/9f418c4767c47d0c71f1727eb42a9a9024e9ecc0/UnityEngine...
}
BaseInput GetBaseInput() {
// Shim this method rather than use reflection, we have access to the EventSystem anyway.
if (EventSystem.current && EventSystem.current.currentInputModule)
return EventSystem.current.currentInputModule.input;
return null;
}
private BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance;
void SetField(string name, T value) {
GetType().BaseType.GetField(name, flags).SetValue(this, value);
}
T GetField(string name) {
return (T)GetType().BaseType.GetField(name, flags).GetValue(this);
}
public void CallMethod(string name) {
GetType().BaseType.GetMethod(name, flags).Invoke(this, null);
}
}