Skip to content

Commit 069188a

Browse files
authored
Merge pull request #9724 from MaxWang-MS/keyboard_updates
Update MRTK keyboard based on Unity 2019.4.25/2020.3.2 fixes
2 parents 3fcb4ee + c7dbcb4 commit 069188a

File tree

6 files changed

+36
-55
lines changed

6 files changed

+36
-55
lines changed

Assets/MRTK/Examples/Demos/HandTracking/Scripts/SystemKeyboardExample.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ namespace Microsoft.MixedReality.Toolkit.Examples.Demos
1212
/// (MixedRealityKeyboard) or Unity's TouchScreenKeyboard API depending on the platform.
1313
/// </summary>
1414
/// <remarks>
15-
/// <para>Note that like Unity's TouchScreenKeyboard API, this script only supports WSA, iOS,
16-
/// and Android.</para>
15+
/// <para>Note that like Unity's TouchScreenKeyboard API, this script only supports WSA, iOS, and Android.</para>
16+
/// <para>If using Unity 2019 or 2020, make sure the version >= 2019.4.25 or 2020.3.2 to ensure the latest fixes for Unity keyboard bugs are present.</para>
1717
/// </remarks>
1818
[AddComponentMenu("Scripts/MRTK/Examples/SystemKeyboardExample")]
1919
public class SystemKeyboardExample : MonoBehaviour

Assets/MRTK/SDK/Experimental/MixedRealityKeyboard/MRTKTMPInputField.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
namespace Microsoft.MixedReality.Toolkit.Experimental.UI
99
{
1010
/// <summary>
11-
/// A derived class of TMP's InputField to workaround with some issues of typing on HoloLens 2
12-
/// No longer used in Unity 2019.3 and later versions.
11+
/// A derived class of TMP's InputField to workaround with some issues of typing on HoloLens 2 specific to Unity 2018.4
1312
/// </summary>
13+
/// <remarks>
14+
/// <para>If using Unity 2019 or 2020, make sure the version >= 2019.4.25 or 2020.3.2 to ensure the latest fixes for Unity keyboard bugs are present.</para>
15+
/// <para>There is a known Unity/TMP issue preventing the caret from showing up. Please see https://github.com/microsoft/MixedRealityToolkit-Unity/issues/9056 for updates.</para>
16+
/// </remarks>
1417
public class MRTKTMPInputField : TMP_InputField
1518
{
1619
#if !UNITY_2019_3_OR_NEWER
Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
using UnityEngine;
54
using UnityEngine.UI;
65

76
#if !UNITY_2019_3_OR_NEWER
@@ -11,38 +10,20 @@
1110
namespace Microsoft.MixedReality.Toolkit.Experimental.UI
1211
{
1312
/// <summary>
14-
/// A derived class of UGUI's InputField to workaround with some issues of typing on HoloLens 2
13+
/// A derived class of UGUI's InputField to workaround with some issues of typing on HoloLens 2 specific to Unity 2018.4
1514
/// </summary>
15+
/// <remarks>
16+
/// <para>If using Unity 2019 or 2020, make sure the version >= 2019.4.25 or 2020.3.2 to ensure the latest fixes for Unity keyboard bugs are present.</para>
17+
/// </remarks>
1618
public class MRTKUGUIInputField : InputField
1719
{
18-
#if UNITY_2019_3_OR_NEWER
19-
[SerializeField]
20-
private bool disableUGUIWorkaround = false;
21-
22-
/// <summary>
23-
/// Currently there is a Unity bug that needs a workaround. Please keep this setting to be false until an announcement of the version of Unity/UGUI that resolves the issue is made.
24-
/// </summary>
25-
public bool DisableUGUIWorkaround
26-
{
27-
get => disableUGUIWorkaround;
28-
set => disableUGUIWorkaround = value;
29-
}
30-
31-
protected override void LateUpdate()
32-
{
33-
if (!DisableUGUIWorkaround && isFocused && m_Keyboard != null && (UnityEngine.Input.GetKeyDown(KeyCode.Backspace)))
34-
{
35-
m_Keyboard.text = m_Text;
36-
}
37-
base.LateUpdate();
38-
}
39-
#else
20+
#if !UNITY_2019_3_OR_NEWER
4021
public int SelectionPosition
4122
{
4223
get => caretSelectPositionInternal;
4324
set => caretSelectPositionInternal = value;
4425
}
4526
public override void OnUpdateSelected(BaseEventData eventData) { }
46-
#endif // UNITY_2019_3_OR_NEWER
27+
#endif // !UNITY_2019_3_OR_NEWER
4728
}
4829
}

Assets/MRTK/SDK/Experimental/MixedRealityKeyboard/MixedRealityKeyboardBase.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ namespace Microsoft.MixedReality.Toolkit.Experimental.UI
2121
/// UWP keyboard from showing up again after it is closed.
2222
/// Unity bug tracking the issue https://fogbugz.unity3d.com/default.asp?1137074_rttdnt8t1lccmtd3
2323
/// </summary>
24+
/// <remarks>
25+
/// <para>If using Unity 2019 or 2020, make sure the version >= 2019.4.25 or 2020.3.2 to ensure the latest fixes for Unity keyboard bugs are present.</para>
26+
/// </remarks>
2427
public abstract class MixedRealityKeyboardBase : MonoBehaviour
2528
{
2629
#region Properties
@@ -187,12 +190,6 @@ private IEnumerator UpdateState()
187190
UpdateText();
188191
}
189192
break;
190-
191-
case KeyboardState.Hiding:
192-
{
193-
onHideKeyboard?.Invoke();
194-
}
195-
break;
196193
}
197194

198195
yield return null;
@@ -262,6 +259,9 @@ public virtual void ShowKeyboard(string text = "", bool multiLine = false)
262259
}
263260

264261
onShowKeyboard?.Invoke();
262+
#if UNITY_2019_3_OR_NEWER
263+
keyboard.selection = new RangeInt(Text.Length, 0);
264+
#endif
265265
MovePreviewCaretToEnd();
266266
if (stateUpdate == null)
267267
{
@@ -290,6 +290,10 @@ private void UpdateText()
290290
{
291291
if (keyboard != null)
292292
{
293+
#if UNITY_2019_3_OR_NEWER
294+
Text = keyboard.text;
295+
CaretIndex = keyboard.selection.end;
296+
#else
293297
// Check the current language of the keyboard
294298
string newKeyboardLanguage = Language.CurrentInputMethodLanguageTag;
295299
if (newKeyboardLanguage != keyboardLanguage)
@@ -367,6 +371,7 @@ private void UpdateText()
367371
}
368372
}
369373

374+
#endif
370375
// Handle commit via the return key.
371376
if (!multiLine)
372377
{
@@ -388,10 +393,8 @@ private void UpdateText()
388393

389394
private void OnKeyboardHiding()
390395
{
391-
if (state != KeyboardState.Hidden)
392-
{
393-
state = KeyboardState.Hiding;
394-
}
396+
UnityEngine.WSA.Application.InvokeOnAppThread(() => onHideKeyboard?.Invoke(), false);
397+
state = KeyboardState.Hidden;
395398
}
396399

397400
private void OnKeyboardShowing() { }

Assets/MRTK/SDK/Experimental/MixedRealityKeyboard/TMP_KeyboardInputField.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ namespace Microsoft.MixedReality.Toolkit.Experimental.UI
1111
{
1212
/// <summary>
1313
/// A component that can be added to InputField to make it work with Windows Mixed Reality's system keyboard.
14-
/// Required when using Unity 2018.4.
14+
/// Only used in Unity 2018.4.
1515
/// No longer used in Unity 2019.3 and later versions (becomes an empty MonoBehaviour and is only around for compatibility) and you can safely remove it if you wish
1616
/// </summary>
17+
/// <remarks>
18+
/// <para>If using Unity 2019 or 2020, make sure the version >= 2019.4.25 or 2020.3.2 to ensure the latest fixes for Unity keyboard bugs are present.</para>
19+
/// <para>There is a known Unity/TMP issue preventing the caret from showing up. Please see https://github.com/microsoft/MixedRealityToolkit-Unity/issues/9056 for updates.</para>
20+
/// </remarks>
1721
#if !UNITY_2019_3_OR_NEWER
1822
[RequireComponent(typeof(MRTKTMPInputField))]
1923
[AddComponentMenu("Scripts/MRTK/Experimental/Keyboard/TMP_KeyboardInputField")]

Assets/MRTK/SDK/Experimental/MixedRealityKeyboard/UI_KeyboardInputField.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ namespace Microsoft.MixedReality.Toolkit.Experimental.UI
1111
{
1212
/// <summary>
1313
/// A component that can be added to InputField to make it work with Windows Mixed Reality's system keyboard.
14-
/// Will no longer be necessary in Unity 2019.3 and later versions after a Unity/UGUI bug is fixed (see disableUGUIWorkaround).
14+
/// Only used in Unity 2018.4.
15+
/// No longer used in Unity 2019.3 and later versions (becomes an empty MonoBehaviour and is only around for compatibility) and you can safely remove it if you wish
1516
/// </summary>
17+
/// <remarks>
18+
/// <para>If using Unity 2019 or 2020, make sure the version >= 2019.4.25 or 2020.3.2 to ensure the latest fixes for Unity keyboard bugs are present.</para>
19+
/// </remarks>
1620
[RequireComponent(typeof(MRTKUGUIInputField))]
1721
[AddComponentMenu("Scripts/MRTK/Experimental/Keyboard/UI_KeyboardInputField")]
1822
public class UI_KeyboardInputField :
@@ -31,20 +35,6 @@ protected override void SyncCaret()
3135
inputField.caretPosition = CaretIndex;
3236
inputField.SelectionPosition = CaretIndex;
3337
}
34-
#else
35-
[SerializeField, Tooltip("Currently there is a Unity bug that needs a workaround. Please keep this setting to be false until an announcement of the version of Unity/UGUI that resolves the issue is made.")]
36-
private bool disableUGUIWorkaround = false;
37-
38-
private MRTKUGUIInputField inputField;
39-
40-
private void OnValidate()
41-
{
42-
if (inputField == null)
43-
{
44-
inputField = GetComponent<MRTKUGUIInputField>();
45-
}
46-
inputField.DisableUGUIWorkaround = disableUGUIWorkaround;
47-
}
4838
#endif
4939
}
5040
}

0 commit comments

Comments
 (0)