// Start is called before the first frame update void Start() { _input = SimpleWebXR.GetInput(Handedness); _input.SelectStart.AddListener(() => gameObject.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f)); _input.SelectEnd.AddListener(() => gameObject.transform.localScale = new Vector3(0.02f, 0.02f, 0.02f)); }
void Start() { _xr = SimpleWebXR.GetInstance(); if (!_xr) { return; } _input = IsLeft ? _xr.LeftInput : _xr.RightInput; _input.SelectStart.AddListener(() => StartCoroutine(DrawCoroutine())); _input.SelectEnd.AddListener(StopAllCoroutines); _renderer = GetComponent <MeshRenderer>(); }
private void UpdateInput(WebXRInput inputSource) { var floatStartId = (int)inputSource.Handedness * 23 + 54; var byteStartId = (int)inputSource.Handedness * 20 + 4; inputSource.Position = ToUnityPosition(_dataArray[floatStartId + 0], _dataArray[floatStartId + 1], _dataArray[floatStartId + 2]); inputSource.Rotation = ToUnityRotation(_dataArray[floatStartId + 3], _dataArray[floatStartId + 4], _dataArray[floatStartId + 5], _dataArray[floatStartId + 6]); inputSource.IsPositionValid = (_byteArray[byteStartId + 0] != 0); var eventId = (int)inputSource.Handedness + 1; var mask = _byteArray[eventId]; if (mask != 0) { RaiseInputSourceEvent(mask, WebXRInputSourceEventTypes.Select, InputSourceSelect, inputSource.Select, inputSource); RaiseInputSourceEvent(mask, WebXRInputSourceEventTypes.SelectEnd, InputSourceSelectEnd, inputSource.SelectEnd, inputSource); RaiseInputSourceEvent(mask, WebXRInputSourceEventTypes.SelectStart, InputSourceSelectStart, inputSource.SelectStart, inputSource); RaiseInputSourceEvent(mask, WebXRInputSourceEventTypes.Squeeze, InputSourceSqueeze, inputSource.Squeeze, inputSource); RaiseInputSourceEvent(mask, WebXRInputSourceEventTypes.SqueezeEnd, InputSourceSqueezeEnd, inputSource.SqueezeEnd, inputSource); RaiseInputSourceEvent(mask, WebXRInputSourceEventTypes.SqueezeStart, InputSourceSqueezeStart, inputSource.SqueezeStart, inputSource); _byteArray[eventId] = 0; } inputSource.TargetRayMode = (WebXRTargetRayModes)_byteArray[byteStartId + 1]; inputSource.AxesCount = _byteArray[byteStartId + 2]; for (int i = 0; i < WebXRInput.AXES_BUTTON_COUNT; i++) { inputSource.Axes[i] = _dataArray[floatStartId + 7 + i]; } inputSource.ButtonsCount = _byteArray[byteStartId + 3]; for (int i = 0; i < WebXRInput.AXES_BUTTON_COUNT; i++) { var button = inputSource.Buttons[i]; button.Value = _dataArray[floatStartId + 15 + i]; button.Touched = _byteArray[byteStartId + 4 + i] != 0; button.Pressed = _byteArray[byteStartId + 12 + i] != 0; } }
protected void UpdateController(WebXRInput controller, Handedness handedness) { if (controller.Available && (controller.IsPositionTracked || controller.Hand.Available)) { if (controller.Hand.Available) { RemoveControllerDevice(handedness); GetOrAddHand(handedness)?.UpdateController(controller); } else { RemoveHandDevice(handedness); GetOrAddController(handedness)?.UpdateController(controller); } } else { RemoveControllerDevice(handedness); RemoveHandDevice(handedness); } }
private void RaiseInputSourceEvent(byte mask, WebXRInputSourceEventTypes type, WebXRInputEvent webxrInputEvent, UnityEvent unityEvent, WebXRInput inputSource) { if (((WebXRInputSourceEventTypes)mask & type) == type) { unityEvent.Invoke(); webxrInputEvent.Invoke(inputSource); Debug.Log($"{inputSource.Handedness} : {type}"); } }
public void UpdateController(WebXRInput controller) { if (!Enabled) { return; } var pose = new MixedRealityPose(controller.Position, controller.Rotation); for (int i = 0; i < Interactions?.Length; i++) { switch (Interactions[i].InputType) { case DeviceInputType.SpatialPointer: Interactions[i].PoseData = pose; if (Interactions[i].Changed) { CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, pose); } break; case DeviceInputType.SpatialGrip: Interactions[i].PoseData = pose; if (Interactions[i].Changed) { CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, pose); } break; case DeviceInputType.Select: Interactions[i].BoolData = controller.Selected; if (Interactions[i].Changed) { if (Interactions[i].BoolData) { CoreServices.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } else { CoreServices.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } } break; case DeviceInputType.TriggerPress: Interactions[i].BoolData = controller.Squeezed; if (Interactions[i].Changed) { if (Interactions[i].BoolData) { CoreServices.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } else { CoreServices.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } } break; } } }
public void UpdateController(WebXRInput controller) { if (!Enabled) { return; } IsPositionAvailable = IsRotationAvailable = controller.Hand.Available; for (int i = 0; i < WebXRHand.JOINT_COUNT; i++) { var joint = controller.Hand.Joints[i]; jointPoses[(TrackedHandJoint)(i + 1)] = new MixedRealityPose(joint.Position, joint.Rotation); } var indexJoint = controller.Hand.Joints[WebXRHand.INDEX_PHALANX_TIP]; var indexPose = new MixedRealityPose(indexJoint.Position, indexJoint.Rotation); bool isSelecting; MixedRealityPose pointerPose; MixedRealityPose currentGripPose; if (controller.IsPositionTracked) { isSelecting = controller.Selected; pointerPose = new MixedRealityPose(controller.Position, controller.Rotation); currentGripPose = pointerPose; } else { isSelecting = Vector3.Distance(controller.Hand.Joints[WebXRHand.THUMB_PHALANX_TIP].Position, controller.Hand.Joints[WebXRHand.INDEX_PHALANX_TIP].Position) < 0.04; currentGripPose = jointPoses[TrackedHandJoint.Wrist]; HandRay.Update((controller.Hand.Joints[WebXRHand.THUMB_PHALANX_TIP].Position + controller.Hand.Joints[WebXRHand.INDEX_PHALANX_TIP].Position) / 2, new Vector3(0.3f, -0.4f, 0.9f), CameraCache.Main.transform, ControllerHandedness); Ray ray = HandRay.Ray; pointerPose = new MixedRealityPose(ray.origin, Quaternion.LookRotation(ray.direction)); } CoreServices.InputSystem?.RaiseSourcePoseChanged(InputSource, this, pointerPose); CoreServices.InputSystem?.RaiseHandJointsUpdated(InputSource, ControllerHandedness, jointPoses); UpdateVelocity(); for (int i = 0; i < Interactions?.Length; i++) { switch (Interactions[i].InputType) { case DeviceInputType.SpatialPointer: Interactions[i].PoseData = pointerPose; if (Interactions[i].Changed) { CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].PoseData); } break; case DeviceInputType.SpatialGrip: Interactions[i].PoseData = currentGripPose; if (Interactions[i].Changed) { CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].PoseData); } break; case DeviceInputType.Select: Interactions[i].BoolData = isSelecting; if (Interactions[i].Changed) { if (Interactions[i].BoolData) { CoreServices.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } else { CoreServices.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } } break; case DeviceInputType.TriggerPress: Interactions[i].BoolData = isSelecting; if (Interactions[i].Changed) { if (Interactions[i].BoolData) { CoreServices.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } else { CoreServices.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction); } } break; case DeviceInputType.IndexFinger: Interactions[i].PoseData = indexPose; if (Interactions[i].Changed) { CoreServices.InputSystem?.RaisePoseInputChanged(InputSource, ControllerHandedness, Interactions[i].MixedRealityInputAction, Interactions[i].PoseData); } break; } } }