@@ -26,11 +26,15 @@ private enum ControllerState
26
26
private bool enableInXR = false ;
27
27
private WebXRState currentXRState = WebXRState . NORMAL ;
28
28
29
+ [ SerializeField ]
30
+ private LayerMask webcamLayer ;
29
31
[ SerializeField ]
30
32
private Transform camerasBase ;
31
33
[ SerializeField ]
32
34
private Transform cameraFollower ;
33
35
[ SerializeField ]
36
+ private Camera [ ] xrCameras ;
37
+ [ SerializeField ]
34
38
private Camera spectatorCamera ;
35
39
[ SerializeField ]
36
40
private Transform spectatorCameraTransform ;
@@ -51,7 +55,9 @@ private enum ControllerState
51
55
[ SerializeField ]
52
56
private GameObject calibrationHintBottom ;
53
57
[ SerializeField ]
54
- private WebXRController webxrController ;
58
+ private WebXRController leftController ;
59
+ [ SerializeField ]
60
+ private WebXRController rightController ;
55
61
56
62
private ControllerState state = ControllerState . None ;
57
63
private float webcamBaseSize = 1f ;
@@ -111,6 +117,7 @@ private IEnumerator ControllerProcess()
111
117
calibrationHintBottom . SetActive ( false ) ;
112
118
webcamParent . localScale = Vector3 . one * WEBCAM_SIZE_CALIBRATION ;
113
119
webcamParent . gameObject . SetActive ( true ) ;
120
+ AddWebcamLayer ( ) ;
114
121
spectatorCameraParent . SetPositionAndRotation ( camerasBase . position , camerasBase . rotation ) ;
115
122
state = ControllerState . SetCameraPoint ;
116
123
while ( state != ControllerState . Ended )
@@ -135,6 +142,7 @@ private IEnumerator ControllerProcess()
135
142
break ;
136
143
case ControllerState . CalcAndSet :
137
144
CalcAndSet ( ) ;
145
+ RemoveWebcamLayer ( ) ;
138
146
state = ControllerState . Playing ;
139
147
break ;
140
148
case ControllerState . Playing :
@@ -156,9 +164,9 @@ private void Ended()
156
164
157
165
private void SetPoint ( Transform point , GameObject hint , ControllerState nextState , GameObject nextHint )
158
166
{
159
- if ( GetControllersButtonDown ( ) )
167
+ if ( GetControllersButtonDown ( out Vector3 position ) )
160
168
{
161
- point . position = webxrController . transform . position ;
169
+ point . position = position ;
162
170
point . gameObject . SetActive ( true ) ;
163
171
hint . SetActive ( false ) ;
164
172
nextHint . SetActive ( true ) ;
@@ -168,10 +176,10 @@ private void SetPoint(Transform point, GameObject hint, ControllerState nextStat
168
176
169
177
private void SetBottomPoint ( )
170
178
{
171
- if ( GetControllersButtonDown ( ) )
179
+ if ( GetControllersButtonDown ( out Vector3 position ) )
172
180
{
173
181
float cameraToTopDistance = Vector3 . Distance ( calibrationPointCamera . position , calibrationPointTop . position ) ;
174
- Vector3 cameraToBottomDirection = ( webxrController . transform . position - calibrationPointCamera . position ) . normalized ;
182
+ Vector3 cameraToBottomDirection = ( position - calibrationPointCamera . position ) . normalized ;
175
183
calibrationPointBottom . position = calibrationPointCamera . position + cameraToBottomDirection * cameraToTopDistance ;
176
184
calibrationPointBottom . gameObject . SetActive ( true ) ;
177
185
calibrationHintBottom . SetActive ( false ) ;
@@ -181,7 +189,7 @@ private void SetBottomPoint()
181
189
182
190
private void Confirm ( )
183
191
{
184
- if ( GetControllersButtonDown ( ) )
192
+ if ( GetControllersButtonDown ( out Vector3 position ) )
185
193
{
186
194
calibrationPointCamera . gameObject . SetActive ( false ) ;
187
195
calibrationPointTop . gameObject . SetActive ( false ) ;
@@ -228,10 +236,40 @@ private void SetCameraPositionRotation()
228
236
spectatorCameraTransform . SetPositionAndRotation ( calibrationPointCamera . position , Quaternion . LookRotation ( plane . normal , up ) * LEFT_STEP_ROTATION ) ;
229
237
}
230
238
231
- bool GetControllersButtonDown ( )
239
+ private bool GetControllersButtonDown ( out Vector3 position )
232
240
{
233
- return ( webxrController . isHandActive || webxrController . isControllerActive )
234
- && ( webxrController . GetButtonDown ( WebXRController . ButtonTypes . Trigger ) ) ;
241
+ bool leftDown = ( leftController . isHandActive || leftController . isControllerActive )
242
+ && leftController . GetButtonDown ( WebXRController . ButtonTypes . Trigger ) ;
243
+ if ( leftDown )
244
+ {
245
+ position = leftController . transform . position ;
246
+ return true ;
247
+ }
248
+ bool rightDown = ( rightController . isHandActive || rightController . isControllerActive )
249
+ && rightController . GetButtonDown ( WebXRController . ButtonTypes . Trigger ) ;
250
+ if ( rightDown )
251
+ {
252
+ position = rightController . transform . position ;
253
+ return true ;
254
+ }
255
+ position = Vector3 . zero ;
256
+ return false ;
257
+ }
258
+
259
+ private void AddWebcamLayer ( )
260
+ {
261
+ for ( int i = 0 ; i < xrCameras . Length ; i ++ )
262
+ {
263
+ xrCameras [ i ] . cullingMask |= webcamLayer ;
264
+ }
265
+ }
266
+
267
+ private void RemoveWebcamLayer ( )
268
+ {
269
+ for ( int i = 0 ; i < xrCameras . Length ; i ++ )
270
+ {
271
+ xrCameras [ i ] . cullingMask &= ~ webcamLayer ;
272
+ }
235
273
}
236
274
}
237
275
}
0 commit comments