-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFindController.cs
More file actions
214 lines (161 loc) · 7.92 KB
/
Copy pathFindController.cs
File metadata and controls
214 lines (161 loc) · 7.92 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
using UnityEngine;
using System.Collections;
/// <summary>
///
/// This class works wiht the "ControllerWrapper" class and is used to receive events from it.
/// To use this class place it on any game object that should receive events from a controller (i.e. - button press)
/// Modify as nessacary.
///
/// This class is far from effecient and may have errors. So you have optimizations or find errors please let me know
/// or better yet provide the solutions.
///
/// </summary>
public class FindController : MonoBehaviour {
//Left controller index reference
uint lt = 0;
uint rt = 0;
public uint controllerIndex;
public bool triggerPressed = false;
public bool steamPressed = false;
public bool menuPressed = false;
public bool padPressed = false;
public bool padTouched = false;
public bool gripped = false;
// private SteamVR_Controller.Device rtController { get { return SteamVR_Controller.Input((int)rt); } }
private SteamVR_Controller.Device rtController;
public void OnEnable() {
SteamVR_Utils.Event.Listen("device_connected", OnDeviceConnected);
SteamVR_Utils.Event.Listen("triggerClicked", OnTriggerClicked);
SteamVR_Utils.Event.Listen("triggerUnclicked", OnTriggerUnclicked);
SteamVR_Utils.Event.Listen("gripClicked", OnGripClicked);
SteamVR_Utils.Event.Listen("gripUnclicked", OnGripUnclicked);
SteamVR_Utils.Event.Listen("padClicked", OnPadClicked);
SteamVR_Utils.Event.Listen("padUnlicked", OnPadUnclicked);
SteamVR_Utils.Event.Listen("menuClicked", OnMenulicked);
SteamVR_Utils.Event.Listen("menuUnclicked", OnMenuUnclicked);
SteamVR_Utils.Event.Listen("padTouched", OnPadTouched);
SteamVR_Utils.Event.Listen("padUntouched", OnPadUntouched);
}
public void OnDisable() {
SteamVR_Utils.Event.Remove("device_connected", OnDeviceConnected);
SteamVR_Utils.Event.Remove("triggerClicked", OnTriggerClicked);
SteamVR_Utils.Event.Remove("triggerUnclicked", OnTriggerUnclicked);
SteamVR_Utils.Event.Remove("gripClicked", OnGripClicked);
SteamVR_Utils.Event.Remove("gripUnclicked", OnGripUnclicked);
SteamVR_Utils.Event.Remove("padClicked", OnPadClicked);
SteamVR_Utils.Event.Remove("padUnlicked", OnPadUnclicked);
SteamVR_Utils.Event.Remove("menuClicked", OnMenulicked);
SteamVR_Utils.Event.Remove("menuUnclicked", OnMenuUnclicked);
SteamVR_Utils.Event.Remove("padTouched", OnPadTouched);
SteamVR_Utils.Event.Remove("padUntouched", OnPadUntouched);
}
private void OnTriggerClicked(params object[] args) {
ControllerEventArgs eventStruct = (ControllerEventArgs)args[0];
Debug.Log("OnTriggerClicked");
Debug.Log("Controller Index is " + eventStruct.controllerIndex);
Debug.Log("The flags are " + eventStruct.flags);
Debug.Log("Touchpad X is " + eventStruct.padX);
Debug.Log("Touchpad Y is " + eventStruct.padY);
DebugTest(eventStruct.controllerIndex);
}
private void OnTriggerUnclicked(params object[] args) {
ControllerEventArgs eventStruct = (ControllerEventArgs)args[0];
Debug.Log("OnTriggerUnclicked");
Debug.Log("Controller Index is " + eventStruct.controllerIndex);
Debug.Log("The flags are " + eventStruct.flags);
Debug.Log("Touchpad X is " + eventStruct.padX);
Debug.Log("Touchpad Y is " + eventStruct.padY);
}
private void OnGripClicked(params object[] args) {
ControllerEventArgs eventStruct = (ControllerEventArgs)args[0];
Debug.Log("OnGripClicked");
Debug.Log("Controller Index is " + eventStruct.controllerIndex);
Debug.Log("The flags are " + eventStruct.flags);
Debug.Log("Touchpad X is " + eventStruct.padX);
Debug.Log("Touchpad Y is " + eventStruct.padY);
}
private void OnGripUnclicked(params object[] args) {
ControllerEventArgs eventStruct = (ControllerEventArgs)args[0];
Debug.Log("OnGripUnclicked");
Debug.Log("Controller Index is " + eventStruct.controllerIndex);
Debug.Log("The flags are " + eventStruct.flags);
Debug.Log("Touchpad X is " + eventStruct.padX);
Debug.Log("Touchpad Y is " + eventStruct.padY);
}
private void OnPadClicked(params object[] args) {
ControllerEventArgs eventStruct = (ControllerEventArgs)args[0];
Debug.Log("OnPadClicked");
Debug.Log("Controller Index is " + eventStruct.controllerIndex);
Debug.Log("The flags are " + eventStruct.flags);
Debug.Log("Touchpad X is " + eventStruct.padX);
Debug.Log("Touchpad Y is " + eventStruct.padY);
}
private void OnPadUnclicked(params object[] args) {
ControllerEventArgs eventStruct = (ControllerEventArgs)args[0];
Debug.Log("OnPadUnclicked");
Debug.Log("Controller Index is " + eventStruct.controllerIndex);
Debug.Log("The flags are " + eventStruct.flags);
Debug.Log("Touchpad X is " + eventStruct.padX);
Debug.Log("Touchpad Y is " + eventStruct.padY);
}
private void OnMenulicked(params object[] args) {
ControllerEventArgs eventStruct = (ControllerEventArgs)args[0];
Debug.Log("OnMenulicked");
Debug.Log("Controller Index is " + eventStruct.controllerIndex);
Debug.Log("The flags are " + eventStruct.flags);
Debug.Log("Touchpad X is " + eventStruct.padX);
Debug.Log("Touchpad Y is " + eventStruct.padY);
}
private void OnMenuUnclicked(params object[] args) {
ControllerEventArgs eventStruct = (ControllerEventArgs)args[0];
Debug.Log("OnMenuUnclicked");
Debug.Log("Controller Index is " + eventStruct.controllerIndex);
Debug.Log("The flags are " + eventStruct.flags);
Debug.Log("Touchpad X is " + eventStruct.padX);
Debug.Log("Touchpad Y is " + eventStruct.padY);
}
private void OnPadTouched(params object[] args) {
ControllerEventArgs eventStruct = (ControllerEventArgs)args[0];
Debug.Log("OnPadTouched");
Debug.Log("Controller Index is " + eventStruct.controllerIndex);
Debug.Log("The flags are " + eventStruct.flags);
Debug.Log("Touchpad X is " + eventStruct.padX);
Debug.Log("Touchpad Y is " + eventStruct.padY);
}
private void OnPadUntouched(params object[] args) {
ControllerEventArgs eventStruct = (ControllerEventArgs)args[0];
Debug.Log("OnPadUntouched");
Debug.Log("Controller Index is " + eventStruct.controllerIndex);
Debug.Log("The flags are " + eventStruct.flags);
Debug.Log("Touchpad X is " + eventStruct.padX);
Debug.Log("Touchpad Y is " + eventStruct.padY);
}
//This gets the index for the contollers.
//TODO get index based on "right/left most" to get accurate results
private void OnDeviceConnected(params object[] args) {
if ((int) args[0] != 0) {
var i = (int)args[0];
bool connected = (bool)args[1];
var vr = SteamVR.instance;
if (connected) {
if (vr.hmd.GetTrackedDeviceClass((uint)i) == Valve.VR.ETrackedDeviceClass.Controller) {
if (rt == 0) {
rt = (uint)i;
Debug.Log("Right Controller index is " + rt);
}else if (lt == 0) {
lt = (uint)i;
Debug.Log("Left controller index is " + lt);
}
}
}
}
}
void DebugTest(uint controllerIndex) {
//Simple usage
if (controllerIndex == rt) {
Debug.Log("Right Trigger pulled");
} else {
Debug.Log("Left Trigger pulled");
}
}
}