Documentation for the Unity C# Library
Loading...
Searching...
No Matches
KeyboardController.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using TMPro;
5using UnityEngine;
6using UnityEngine.UI;
7
8namespace PixoVR.Login
9{
10 public class KeyboardController : MonoBehaviour
11 {
12 private static bool shifted = false;
13 public static bool capsShifted = false;
14 public static TMP_InputField current;
15 [SerializeField]
16 static AudioSource audioSource;
17 public delegate void ClickAction(bool value);
18 public static event ClickAction OnShifted;
19 private bool started;
20 public void SetInputField(TMP_InputField select)
21 {
22 current = select;
23 }
24 public static bool Shifted
25 {
26 get
27 { return shifted; }
28 set
29 {
30 shifted = value;
31 PlaySound();
32 if (OnShifted != null)
33 OnShifted(value);
34 }
35 }
36 private static void PlaySound()
37 {
38 if (audioSource)
39 {
40 audioSource.Play();
41 }
42 }
43#if UNITY_EDITOR
44 private void OnValidate()
45 {
46 if (started)
47 return;
48 audioSource = GetComponent<AudioSource>();
49 }
50#endif
51 public static void Back()
52 {
53 if (!current)
54 return;
55 if (current.text.Length > 0)
56 {
57 current.text = current.text.Substring(0, current.text.Length - 1);
58 }
59 // Shifted = false;
60 PlaySound();
61 current.caretPosition = current.text.Length;
62
63 }
64 public static void AddCharacter(string addChar)
65 {
66 if (!current)
67 return;
68 current.text += addChar;
69 if (!capsShifted)
70 {
71 Shifted = false;
72 }
73 PlaySound();
74 current.caretPosition = current.text.Length;
75 //.text = current.text.Substring(0, current.text.Length - 1);//update cursor
76 }
77 void Awake()
78 {
79 started = true;
80 }
81 }
82}
void SetInputField(TMP_InputField select)
static void AddCharacter(string addChar)
delegate void ClickAction(bool value)
static AudioSource audioSource
[SerializeField]