-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathKeypadButton.cs
More file actions
98 lines (85 loc) · 2.57 KB
/
KeypadButton.cs
File metadata and controls
98 lines (85 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
// ReSharper disable MemberCanBeMadeStatic.Local
// ReSharper disable once CheckNamespace
public class KeypadButton : UdonSharpBehaviour
{
public Keypad keypad = null;
public string buttonValue = null;
public bool disableDebugging = false;
private string _buttonId;
private string _prefix;
#region Util Functions
private void Log(string value)
{
if (disableDebugging != true)
{
Debug.Log(_prefix + value);
}
}
private void LogError(string value)
{
if (disableDebugging != true)
{
Debug.LogError(_prefix + value);
}
}
private void Die()
{
// Crash.
// ReSharper disable once PossibleNullReferenceException
// ReSharper disable once ReturnValueOfPureMethodIsNotUsed
((string) null).ToString();
}
#endregion Util Functions
public void Start()
{
// ReSharper disable once SpecifyACultureInStringConversionExplicitly
_buttonId = Random.value.ToString();
_prefix = "[UdonKeypad] [b-" + _buttonId + "] ";
Log("Loading button... Value: " + buttonValue);
if (keypad == null)
{
LogError("Keypad is not set! Trying to dynamically find object...");
var obj = GameObject.Find("Keypad");
if (obj != null)
{
keypad = (Keypad) obj.GetComponent(typeof(UdonBehaviour));
}
else
{
LogError("Keypad is not set and could not dynamically find parent! Dying...");
Die();
}
}
if (buttonValue == null)
{
LogError("Keypad is not set! Resetting to calculated value: " + gameObject.name.Substring(12));
buttonValue = gameObject.name.Substring(12);
}
if (buttonValue.Length != 1 && buttonValue != "OK" && buttonValue != "CLR")
{
LogError("Button has invalid value! Resetting to 'X'. OldValue: '" + buttonValue + "'.");
buttonValue = "X";
}
Log("Button started! Value: " + buttonValue);
}
public override void Interact()
{
if (Networking.LocalPlayer != null && Networking.LocalPlayer.IsUserInVR())
{
ButtonPressed();
}
}
public void OnMouseDown()
{
ButtonPressed();
}
private void ButtonPressed()
{
Log("Key pressed: " + buttonValue);
keypad.ButtonInput(buttonValue);
}
}