Documentation for the Unity C# Library
Loading...
Searching...
No Matches
LetterKey.cs
Go to the documentation of this file.
1
2using UnityEngine;
3using System.Collections;
4using UnityEngine.UI;
5using TMPro;
6
7namespace PixoVR.Login
8{
9
13 public class LetterKey : MonoBehaviour
14 {
15 public TextMeshProUGUI label;
16 public TextMeshProUGUI shiftedLabel;
17
18 public string character = "";
19
20 public string shiftedChar = "";
21 [SerializeField]
22 Button btn;
23 // private bool _shifted = false;
24 private bool started;
25 [SerializeField]
26 bool refresh;
27#if UNITY_EDITOR
28 private void OnValidate()
29 {
30 refresh = false;
31 if (started)
32 return;
33 btn = transform.GetComponentInChildren<Button>();
34 label = btn.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>();
35 if (label)
36 label.text = character;
37 if (btn.transform.childCount > 1)
38 {
39 shiftedLabel = btn.transform.GetChild(1).gameObject.GetComponent<TextMeshProUGUI>();
40 if (shiftedLabel)
41 shiftedLabel.text = shiftedChar;
42 }
43 else
44 {
45 shiftedLabel = null;
46
47 }
48 }
49#endif
50 private void Awake()
51 {
52 started = true;
53 btn.onClick.AddListener(OnClick);
54 KeyboardController.OnShifted += OnShifted;
55 }
56 private void OnDestroy()
57 {
58 KeyboardController.OnShifted -= OnShifted;
59 }
60 private void OnShifted(bool value)
61 {
63 label.gameObject.SetActive(!value);
64 if (shiftedLabel)
65 shiftedLabel.gameObject.SetActive(value);
66 }
67 public bool shifted
68 {
69 get { return KeyboardController.Shifted; }
70 }
71
72 public string GetCharacter()
73 {
74 return KeyboardController.Shifted ? shiftedChar : character;
75 }
76 public void OnClick()
77 {
static void AddCharacter(string addChar)
An individual letter key.
Definition LetterKey.cs:14
TextMeshProUGUI label
Definition LetterKey.cs:15
Button btn
[SerializeField]
Definition LetterKey.cs:25
void OnShifted(bool value)
Definition LetterKey.cs:66
bool refresh
[SerializeField]
Definition LetterKey.cs:32
TextMeshProUGUI shiftedLabel
Definition LetterKey.cs:16