AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
KeyboardInputField.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using System;
5 using UnityEngine;
6 using UnityEngine.EventSystems;
7 using UnityEngine.UI;
8 
9 namespace HoloToolkit.UI.Keyboard
10 {
14  public class KeyboardInputField : InputField
15  {
19  [Header("Keyboard Settings")]
20  public Transform KeyboardSpawnPoint;
21 
25  [HideInInspector]
26  public Keyboard.LayoutType KeyboardLayout = Keyboard.LayoutType.Alpha;
27 
28  private const float KeyBoardPositionOffset = 0.045f;
29 
33  public override void OnPointerClick(PointerEventData eventData)
34  {
35  base.OnPointerClick(eventData);
36 
37  if (!TouchScreenKeyboard.isSupported)
38  {
39  Keyboard.Instance.Close();
40  Keyboard.Instance.PresentKeyboard(text, KeyboardLayout);
41 
42  if (KeyboardSpawnPoint != null)
43  {
44  Keyboard.Instance.RepositionKeyboard(KeyboardSpawnPoint, null, KeyBoardPositionOffset);
45  }
46  else
47  {
48  Keyboard.Instance.RepositionKeyboard(transform, null, KeyBoardPositionOffset);
49  }
50 
51  // Subscribe to keyboard delegates
52  Keyboard.Instance.OnTextUpdated += Keyboard_OnTextUpdated;
53  Keyboard.Instance.OnClosed += Keyboard_OnClosed;
54  }
55  }
56 
61  private void Keyboard_OnTextUpdated(string newText)
62  {
63  text = newText;
64  }
65 
70  private void Keyboard_OnClosed(object sender, EventArgs e)
71  {
72  // Unsubscribe from delegate functions
73  Keyboard.Instance.OnTextUpdated -= Keyboard_OnTextUpdated;
74  Keyboard.Instance.OnClosed -= Keyboard_OnClosed;
75  }
76  }
77 }
Class that when placed on an input field will enable keyboard on click
LayoutType
Layout type enum for the type of keyboard layout to use. This is used when spawning to enable the cor...
Definition: Keyboard.cs:27
A simple general use keyboard that is ideal for AR/VR applications.
Definition: Keyboard.cs:21
Transform KeyboardSpawnPoint
Internal field for overriding keyboard spawn point
static T Instance
Returns the Singleton instance of the classes type. If no instance is found, then we search for an in...
Definition: Singleton.cs:26
override void OnPointerClick(PointerEventData eventData)
Override OnPointerClick to spawn keyboard