AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
KeyboardValueKey.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 UnityEngine;
5 using UnityEngine.UI;
6 
7 namespace HoloToolkit.UI.Keyboard
8 {
12  [RequireComponent(typeof(Button))]
13  public class KeyboardValueKey : MonoBehaviour
14  {
18  public string Value;
19 
23  public string ShiftValue;
24 
28  private Text m_Text;
29 
33  private Button m_Button;
34 
38  private void Awake()
39  {
40  m_Button = GetComponent<Button>();
41  }
42 
46  private void Start()
47  {
48  m_Text = gameObject.GetComponentInChildren<Text>();
49  m_Text.text = Value;
50 
51  m_Button.onClick.RemoveAllListeners();
52  m_Button.onClick.AddListener(FireAppendValue);
53 
54  Keyboard.Instance.OnKeyboardShifted += Shift;
55  }
56 
60  private void FireAppendValue()
61  {
62  Keyboard.Instance.AppendValue(this);
63  }
64 
69  public void Shift(bool isShifted)
70  {
71  // Shift value should only be applied if a shift value is present.
72  if (isShifted && !string.IsNullOrEmpty(ShiftValue))
73  {
74  m_Text.text = ShiftValue;
75  }
76  else
77  {
78  m_Text.text = Value;
79  }
80  }
81  }
82 }
string Value
The default string value for this key.
A simple general use keyboard that is ideal for AR/VR applications.
Definition: Keyboard.cs:21
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
void Shift(bool isShifted)
Called by the Keyboard when the shift key is pressed. Updates the text for this key using the Value a...
Represents a key on the keyboard that has a string value for input.
string ShiftValue
The shifted string value for this key.