Esempio n. 1
0
        private void OnControllerUpdate(WebXRControllerData controllerData)
        {
            if (controllerData.hand == (int)hand)
            {
                if (!controllerData.enabled)
                {
                    SetVisible(false);
                    return;
                }
                SetVisible(true);

                transform.localRotation = controllerData.rotation;
                transform.localPosition = controllerData.position;

                trigger     = controllerData.trigger;
                squeeze     = controllerData.squeeze;
                thumbstick  = controllerData.thumbstick;
                thumbstickX = controllerData.thumbstickX;
                thumbstickY = controllerData.thumbstickY;
                touchpad    = controllerData.touchpad;
                touchpadX   = controllerData.touchpadX;
                touchpadY   = controllerData.touchpadY;
                buttonA     = controllerData.buttonA;
                buttonB     = controllerData.buttonB;

                WebXRControllerButton[] buttons = new WebXRControllerButton[6];
                buttons[0] = new WebXRControllerButton(trigger == 1, trigger);
                buttons[1] = new WebXRControllerButton(squeeze == 1, squeeze);
                buttons[2] = new WebXRControllerButton(thumbstick == 1, thumbstick);
                buttons[3] = new WebXRControllerButton(touchpad == 1, touchpad);
                buttons[4] = new WebXRControllerButton(buttonA == 1, buttonA);
                buttons[5] = new WebXRControllerButton(buttonB == 1, buttonB);
                UpdateButtons(buttons);
            }
        }
Esempio n. 2
0
        private void OnHandUpdateInternal(WebXRHandData handData)
        {
            if (handData.hand == (int)hand)
            {
                if (!handData.enabled)
                {
                    SetHandActive(false);
                    return;
                }
                SetControllerActive(false);
                SetHandActive(true);

                transform.localPosition = handData.joints[0].position;
                transform.localRotation = handData.joints[0].rotation;

                Quaternion rotationOffset = Quaternion.Inverse(handData.joints[0].rotation);

                trigger = handData.trigger;
                squeeze = handData.squeeze;

                WebXRControllerButton[] buttons = new WebXRControllerButton[2];
                buttons[(int)ButtonTypes.Trigger] = new WebXRControllerButton(trigger == 1, trigger);
                buttons[(int)ButtonTypes.Grip]    = new WebXRControllerButton(squeeze == 1, squeeze);
                UpdateButtons(buttons);

                OnHandUpdate?.Invoke(handData);
            }
        }
Esempio n. 3
0
 // Updates button states from Web gamepad API.
 private void UpdateButtons(WebXRControllerButton[] buttons)
 {
     for (int i = 0; i < buttons.Length; i++)
     {
         WebXRControllerButton button = buttons[i];
         SetButtonState((ButtonTypes)i, button.pressed, button.value);
     }
 }
Esempio n. 4
0
        private void OnHandUpdate(WebXRHandData handData)
        {
            if (handData.hand == (int)hand)
            {
                if (!handData.enabled)
                {
                    SetHandJointsVisible(false);
                    return;
                }
                SetVisible(false);
                SetHandJointsVisible(true);

                transform.localPosition = handData.joints[0].position;
                transform.localRotation = handData.joints[0].rotation;

                Quaternion rotationOffset = Quaternion.Inverse(handData.joints[0].rotation);

                for (int i = 0; i <= WebXRHandData.LITTLE_PHALANX_TIP; i++)
                {
                    if (handData.joints[i].enabled)
                    {
                        if (handJoints.ContainsKey(i))
                        {
                            handJoints[i].localPosition = rotationOffset * (handData.joints[i].position - handData.joints[0].position);
                            handJoints[i].localRotation = rotationOffset * handData.joints[i].rotation;
                        }
                        else
                        {
                            var clone = Instantiate(handJointPrefab,
                                                    rotationOffset * (handData.joints[i].position - handData.joints[0].position),
                                                    rotationOffset * handData.joints[i].rotation,
                                                    transform);
                            if (handData.joints[i].radius > 0f)
                            {
                                clone.localScale = new Vector3(handData.joints[i].radius, handData.joints[i].radius, handData.joints[i].radius);
                            }
                            else
                            {
                                clone.localScale = new Vector3(0.005f, 0.005f, 0.005f);
                            }
                            handJoints.Add(i, clone);
                        }
                    }
                }

                trigger = handData.trigger;
                squeeze = handData.squeeze;

                WebXRControllerButton[] buttons = new WebXRControllerButton[2];
                buttons[0] = new WebXRControllerButton(trigger == 1, trigger);
                buttons[1] = new WebXRControllerButton(squeeze == 1, squeeze);
                UpdateButtons(buttons);
            }
        }
Esempio n. 5
0
 // Updates button states from Web gamepad API.
 private void UpdateButtons(WebXRControllerButton[] buttons)
 {
     for (int i = 0; i < buttons.Length; i++)
     {
         WebXRControllerButton button = buttons[i];
         foreach (var input in inputMap.inputs)
         {
             if (input.gamepadId == i)
             {
                 SetButtonState(input.actionName, button.pressed, button.value);
             }
         }
     }
 }
Esempio n. 6
0
        private void OnControllerUpdate(WebXRControllerData controllerData)
        {
            if (controllerData.hand == (int)hand)
            {
                if (!controllerData.enabled)
                {
                    SetControllerActive(false);
                    return;
                }

                profiles = controllerData.profiles;

                transform.localRotation = controllerData.rotation;
                transform.localPosition = controllerData.position;

                trigger     = controllerData.trigger;
                squeeze     = controllerData.squeeze;
                thumbstick  = controllerData.thumbstick;
                thumbstickX = controllerData.thumbstickX;
                thumbstickY = controllerData.thumbstickY;
                touchpad    = controllerData.touchpad;
                touchpadX   = controllerData.touchpadX;
                touchpadY   = controllerData.touchpadY;
                buttonA     = controllerData.buttonA;
                buttonB     = controllerData.buttonB;

                WebXRControllerButton[] buttons = new WebXRControllerButton[6];
                buttons[(int)ButtonTypes.Trigger]    = new WebXRControllerButton(trigger == 1, trigger);
                buttons[(int)ButtonTypes.Grip]       = new WebXRControllerButton(squeeze == 1, squeeze);
                buttons[(int)ButtonTypes.Thumbstick] = new WebXRControllerButton(thumbstick == 1, thumbstick);
                buttons[(int)ButtonTypes.Touchpad]   = new WebXRControllerButton(touchpad == 1, touchpad);
                buttons[(int)ButtonTypes.ButtonA]    = new WebXRControllerButton(buttonA == 1, buttonA);
                buttons[(int)ButtonTypes.ButtonB]    = new WebXRControllerButton(buttonB == 1, buttonB);
                UpdateButtons(buttons);

                SetControllerActive(true);
            }
        }
Esempio n. 7
0
        public void TryUpdateButtons()
        {
#if UNITY_EDITOR
            if (!WebXRManager.Instance.isSubsystemAvailable && inputDevice != null)
            {
                inputDevice.Value.TryGetFeatureValue(CommonUsages.trigger, out trigger);
                inputDevice.Value.TryGetFeatureValue(CommonUsages.grip, out squeeze);
                if (trigger <= 0.02)
                {
                    trigger = 0;
                }
                else if (trigger >= 0.98)
                {
                    trigger = 1;
                }

                if (squeeze <= 0.02)
                {
                    squeeze = 0;
                }
                else if (squeeze >= 0.98)
                {
                    squeeze = 1;
                }

                Vector2 axis2D;
                if (inputDevice.Value.TryGetFeatureValue(CommonUsages.primary2DAxis, out axis2D))
                {
                    thumbstickX = axis2D.x;
                    thumbstickY = axis2D.y;
                }
                if (inputDevice.Value.TryGetFeatureValue(CommonUsages.secondary2DAxis, out axis2D))
                {
                    touchpadX = axis2D.x;
                    touchpadY = axis2D.y;
                }
                bool buttonPressed;
                if (inputDevice.Value.TryGetFeatureValue(CommonUsages.primary2DAxisClick, out buttonPressed))
                {
                    thumbstick = buttonPressed ? 1 : 0;
                }
                if (inputDevice.Value.TryGetFeatureValue(CommonUsages.secondary2DAxisClick, out buttonPressed))
                {
                    touchpad = buttonPressed ? 1 : 0;
                }
                if (inputDevice.Value.TryGetFeatureValue(CommonUsages.primaryButton, out buttonPressed))
                {
                    buttonA = buttonPressed ? 1 : 0;
                }
                if (inputDevice.Value.TryGetFeatureValue(CommonUsages.secondaryButton, out buttonPressed))
                {
                    buttonB = buttonPressed ? 1 : 0;
                }

                WebXRControllerButton[] buttons = new WebXRControllerButton[6];
                buttons[0] = new WebXRControllerButton(trigger == 1, trigger);
                buttons[1] = new WebXRControllerButton(squeeze == 1, squeeze);
                buttons[2] = new WebXRControllerButton(thumbstick == 1, thumbstick);
                buttons[3] = new WebXRControllerButton(touchpad == 1, touchpad);
                buttons[4] = new WebXRControllerButton(buttonA == 1, buttonA);
                buttons[5] = new WebXRControllerButton(buttonB == 1, buttonB);
                UpdateButtons(buttons);
            }
#endif
        }
Esempio n. 8
0
        private void TryUpdateButtons()
        {
#if UNITY_EDITOR || !UNITY_WEBGL
            if (buttonsFrameUpdate == Time.frameCount)
            {
                return;
            }
            buttonsFrameUpdate = Time.frameCount;
            if (!WebXRManager.Instance.isSubsystemAvailable && inputDevice != null)
            {
                inputDevice.Value.TryGetFeatureValue(CommonUsages.trigger, out trigger);
                inputDevice.Value.TryGetFeatureValue(CommonUsages.grip, out squeeze);
                if (trigger <= 0.02)
                {
                    trigger = 0;
                }
                else if (trigger >= 0.98)
                {
                    trigger = 1;
                }

                if (squeeze <= 0.02)
                {
                    squeeze = 0;
                }
                else if (squeeze >= 0.98)
                {
                    squeeze = 1;
                }

                Vector2 axis2D;
                if (inputDevice.Value.TryGetFeatureValue(CommonUsages.primary2DAxis, out axis2D))
                {
                    thumbstickX = axis2D.x;
                    thumbstickY = axis2D.y;
                }
                if (inputDevice.Value.TryGetFeatureValue(CommonUsages.secondary2DAxis, out axis2D))
                {
                    touchpadX = axis2D.x;
                    touchpadY = axis2D.y;
                }
                bool buttonPressed;
                if (inputDevice.Value.TryGetFeatureValue(CommonUsages.primary2DAxisClick, out buttonPressed))
                {
                    thumbstick = buttonPressed ? 1 : 0;
                }
                if (inputDevice.Value.TryGetFeatureValue(CommonUsages.secondary2DAxisClick, out buttonPressed))
                {
                    touchpad = buttonPressed ? 1 : 0;
                }
                if (inputDevice.Value.TryGetFeatureValue(CommonUsages.primaryButton, out buttonPressed))
                {
                    buttonA = buttonPressed ? 1 : 0;
                }
                if (inputDevice.Value.TryGetFeatureValue(CommonUsages.secondaryButton, out buttonPressed))
                {
                    buttonB = buttonPressed ? 1 : 0;
                }

                WebXRControllerButton[] buttons = new WebXRControllerButton[6];
                buttons[(int)ButtonTypes.Trigger]    = new WebXRControllerButton(trigger == 1, trigger);
                buttons[(int)ButtonTypes.Grip]       = new WebXRControllerButton(squeeze == 1, squeeze);
                buttons[(int)ButtonTypes.Thumbstick] = new WebXRControllerButton(thumbstick == 1, thumbstick);
                buttons[(int)ButtonTypes.Touchpad]   = new WebXRControllerButton(touchpad == 1, touchpad);
                buttons[(int)ButtonTypes.ButtonA]    = new WebXRControllerButton(buttonA == 1, buttonA);
                buttons[(int)ButtonTypes.ButtonB]    = new WebXRControllerButton(buttonB == 1, buttonB);
                UpdateButtons(buttons);
            }
#endif
        }
        private void OnControllerUpdate(WebXRControllerData controllerData)
        {
            if (controllerData.hand == (int)hand)
            {
                if (!controllerData.enabled)
                {
                    SetControllerActive(false);
                    return;
                }

                profiles = controllerData.profiles;

                if (oculusLinkBugTest != 1)
                {
                    gripRotation = controllerData.gripRotation;
                    gripPosition = controllerData.gripPosition;
                    if (alwaysUseGrip)
                    {
                        transform.localRotation = controllerData.rotation * controllerData.gripRotation;
                        transform.localPosition = controllerData.rotation * (controllerData.position + controllerData.gripPosition);
                    }
                    else
                    {
                        transform.localRotation = controllerData.rotation;
                        transform.localPosition = controllerData.position;
                    }
                    // Oculus on desktop returns wrong rotation for targetRaySpace, this is an ugly hack to fix it
                    if (CheckOculusLinkBug())
                    {
                        HandleOculusLinkBug(controllerData);
                    }
                }
                else
                {
                    // Oculus on desktop returns wrong rotation for targetRaySpace, this is an ugly hack to fix it
                    HandleOculusLinkBug(controllerData);
                }

                trigger     = controllerData.trigger;
                squeeze     = controllerData.squeeze;
                thumbstick  = controllerData.thumbstick;
                thumbstickX = controllerData.thumbstickX;
                thumbstickY = controllerData.thumbstickY;
                touchpad    = controllerData.touchpad;
                touchpadX   = controllerData.touchpadX;
                touchpadY   = controllerData.touchpadY;
                buttonA     = controllerData.buttonA;
                buttonB     = controllerData.buttonB;

                WebXRControllerButton[] buttons = new WebXRControllerButton[6];
                buttons[(int)ButtonTypes.Trigger]    = new WebXRControllerButton(trigger == 1, trigger);
                buttons[(int)ButtonTypes.Grip]       = new WebXRControllerButton(squeeze == 1, squeeze);
                buttons[(int)ButtonTypes.Thumbstick] = new WebXRControllerButton(thumbstick == 1, thumbstick);
                buttons[(int)ButtonTypes.Touchpad]   = new WebXRControllerButton(touchpad == 1, touchpad);
                buttons[(int)ButtonTypes.ButtonA]    = new WebXRControllerButton(buttonA == 1, buttonA);
                buttons[(int)ButtonTypes.ButtonB]    = new WebXRControllerButton(buttonB == 1, buttonB);
                UpdateButtons(buttons);

                SetControllerActive(true);
            }
        }