Skip to content

Commit bac7988

Browse files
committed
More bug fixes, adapt SceneHitTest to the Input System
1 parent e2a4e4b commit bac7988

File tree

4 files changed

+575
-8
lines changed

4 files changed

+575
-8
lines changed

Packages/webxr-interactions/Runtime/InputSystem/WebXRControllerModel.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ public UpdateType updateType
161161
private bool visualActionsInit;
162162
bool m_IsFirstUpdate = true;
163163

164+
private Transform xrControllerOldModel;
165+
164166
#if WEBXR_INPUT_PROFILES
165167
void BindActions()
166168
{
@@ -415,9 +417,10 @@ protected void OnDisable()
415417
WebXRInputSystem.OnRightControllerProfiles -= HandleOnControllerProfiles;
416418
break;
417419
}
418-
if (xrController != null && xrController.model != null)
420+
if (xrController != null && xrControllerOldModel != null)
419421
{
420-
xrController.model.gameObject.SetActive(true);
422+
xrController.model = xrControllerOldModel;
423+
xrController.hideControllerModel = false;
421424
}
422425
}
423426

@@ -633,7 +636,9 @@ private void HandleModelLoaded(bool success)
633636
inputProfileModelTransform.localScale = Vector3.one;
634637
if (xrController != null && xrController.model != null)
635638
{
636-
xrController.model.gameObject.SetActive(false);
639+
xrControllerOldModel = xrController.model;
640+
xrController.hideControllerModel = true;
641+
xrController.model = null;
637642
}
638643

639644
if (m_CurrentTrackingState == TrackingStates.None)

Packages/webxr-interactions/Runtime/Scripts/MixedRealityCaptureController.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,13 @@ private void SetPoint(Transform point, GameObject hint, ControllerState nextStat
338338
private void SetBottomPoint()
339339
{
340340
float cameraToTopDistance = Vector3.Distance(calibrationPointCamera.position, calibrationPointTop.position);
341+
#if UNITY_INPUT_SYSTEM_1_4_4_OR_NEWER
341342
Vector3 cameraToBottomDirection = useInputSystem ?
342343
(rightPosition.action.ReadValue<Vector3>() - calibrationPointCamera.position).normalized
343344
: (rightController.transform.position - calibrationPointCamera.position).normalized;
345+
#else
346+
Vector3 cameraToBottomDirection = (rightController.transform.position - calibrationPointCamera.position).normalized;
347+
#endif
344348
calibrationPointBottom.position = calibrationPointCamera.position + cameraToBottomDirection * cameraToTopDistance;
345349
if (GetControllersButtonDown())
346350
{
@@ -406,14 +410,13 @@ private void SetCameraPositionRotation()
406410

407411
private bool GetControllersButtonDown()
408412
{
413+
#if UNITY_INPUT_SYSTEM_1_4_4_OR_NEWER
409414
if (useInputSystem)
410415
{
411-
if (leftTrigger.action.ReadValue<bool>())
412-
{
413-
return true;
414-
}
415-
return rightTrigger.action.ReadValue<bool>();
416+
return leftTrigger.action.ReadValue<bool>()
417+
|| rightTrigger.action.ReadValue<bool>();
416418
}
419+
#endif
417420
bool leftDown = (leftController.isHandActive || leftController.isControllerActive)
418421
&& leftController.GetButtonDown(WebXRController.ButtonTypes.Trigger);
419422
if (leftDown)

Packages/webxr-interactions/Runtime/Scripts/SceneHitTest.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ public class SceneHitTest : MonoBehaviour
1010
private WebXRController leftController;
1111
[SerializeField]
1212
private WebXRController rightController;
13+
#if UNITY_INPUT_SYSTEM_1_4_4_OR_NEWER
14+
[SerializeField]
15+
#endif
16+
private bool useInputSystem = false;
17+
#if UNITY_INPUT_SYSTEM_1_4_4_OR_NEWER
18+
[SerializeField]
19+
private UnityEngine.InputSystem.InputActionProperty leftTrigger;
20+
[SerializeField]
21+
private UnityEngine.InputSystem.InputActionProperty rightTrigger;
22+
#endif
1323

1424
private bool isFollowing = false;
1525

@@ -20,6 +30,10 @@ public class SceneHitTest : MonoBehaviour
2030

2131
void Start()
2232
{
33+
if (useInputSystem)
34+
{
35+
return;
36+
}
2337
if (leftController == null || rightController == null)
2438
{
2539
var controllers = FindObjectsOfType<WebXRController>();
@@ -59,6 +73,13 @@ void OnDisable()
5973

6074
bool GetControllersButtonDown()
6175
{
76+
#if UNITY_INPUT_SYSTEM_1_4_4_OR_NEWER
77+
if (useInputSystem)
78+
{
79+
return leftTrigger.action.ReadValue<bool>()
80+
|| rightTrigger.action.ReadValue<bool>();
81+
}
82+
#endif
6283
bool leftDown = (leftController.isHandActive || leftController.isControllerActive) && leftController.GetButtonDown(WebXRController.ButtonTypes.Trigger);
6384
bool rightDown = (rightController.isHandActive || rightController.isControllerActive) && rightController.GetButtonDown(WebXRController.ButtonTypes.Trigger);
6485
return leftDown || rightDown;

0 commit comments

Comments
 (0)