示例#1
0
        public void Update()
        {
            // Manually update the Touch input
            OVRInput.Update();

            if ((OVRInput.GetActiveController() & OVRInput.Controller.Touch) == 0)
            {
                active = false;
                return;
            }
            active = true;

            for (VRInputDevice.Handedness hand = VRInputDevice.Handedness.Left;
                 (int)hand <= (int)VRInputDevice.Handedness.Right;
                 hand++)
            {
                OVRInput.Controller controller = hand == VRInputDevice.Handedness.Left
                                        ? OVRInput.Controller.LTouch
                                        : OVRInput.Controller.RTouch;
                int ovrIndex    = controller == OVRInput.Controller.LTouch ? 0 : 1;
                int deviceIndex = hand == VRInputDevice.Handedness.Left ? 3 : 4;

                // TODO change 3 and 4 based on virtual devices defined in InputDeviceManager (using actual hardware available)
                SendButtonEvents(controller, deviceIndex);
                SendAxisEvents(controller, ovrIndex, deviceIndex);
                SendTrackingEvents(controller, ovrIndex, deviceIndex);
            }
        }
        public void Update()
        {
            var deviceActive = false;

            foreach (var device in UnityEngine.Input.GetJoystickNames())
            {
                if (device.IndexOf(DeviceName, StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    deviceActive = true;
                    break;
                }
            }

            active = deviceActive;
            if (!active)
            {
                return;
            }

            for (VRInputDevice.Handedness hand = VRInputDevice.Handedness.Left;
                 (int)hand <= (int)VRInputDevice.Handedness.Right;
                 hand++)
            {
                int deviceIndex = hand == VRInputDevice.Handedness.Left ? 3 : 4;

                // TODO change 3 and 4 based on virtual devices defined in InputDeviceManager (using actual hardware available)
                SendButtonEvents(hand, deviceIndex);
                SendAxisEvents(hand, deviceIndex);
                SendTrackingEvents(hand, deviceIndex);
            }
        }
        void SendAxisEvents(VRInputDevice.Handedness hand, int deviceIndex)
        {
            for (var axis = 0; axis < k_AxisCount; ++axis)
            {
                float value;
                if (GetAxis(hand, (VRInputDevice.VRControl)axis, out value))
                {
                    if (Mathf.Approximately(m_LastAxisValues[(int)hand, axis], value))
                    {
                        continue;
                    }

                    if (Mathf.Abs(value) < k_DeadZone)
                    {
                        value = 0;
                    }

                    var inputEvent = InputSystem.CreateEvent <GenericControlEvent>();
                    inputEvent.deviceType   = typeof(VRInputDevice);
                    inputEvent.deviceIndex  = deviceIndex;
                    inputEvent.controlIndex = axis;
                    inputEvent.value        = value;

                    m_LastAxisValues[(int)hand, axis] = inputEvent.value;

                    InputSystem.QueueEvent(inputEvent);
                }
            }
        }
示例#4
0
        public void Update()
        {
            var isActive = false;

            TrackedDevicePose_t[] poses = null;
            var compositor = OpenVR.Compositor;

            if (compositor != null)
            {
                var render = SteamVR_Render.instance;
                render.transform.parent = gameObject.transform;
                compositor.GetLastPoses(render.poses, render.gamePoses);
                poses = render.poses;
            }

            var leftSteamDeviceIndex  = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost);
            var rightSteamDeviceIndex = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost);

            if (leftSteamDeviceIndex == -1 || rightSteamDeviceIndex == -1 || leftSteamDeviceIndex == rightSteamDeviceIndex)
            {
                return;
            }

            // Oculus Touch on OpenVR should have fixed left/right hand device indices
            if (XRDevice.model.IndexOf("oculus", StringComparison.OrdinalIgnoreCase) >= 0 &&
                leftSteamDeviceIndex > rightSteamDeviceIndex)
            {
                var swap = rightSteamDeviceIndex;
                rightSteamDeviceIndex = leftSteamDeviceIndex;
                leftSteamDeviceIndex  = swap;
            }

            for (VRInputDevice.Handedness hand = VRInputDevice.Handedness.Left; (int)hand <= (int)VRInputDevice.Handedness.Right; hand++)
            {
                var steamDeviceIndex = steamDeviceIndices[(int)hand];

                if (steamDeviceIndex == -1)
                {
                    steamDeviceIndices[(int)hand] = hand == VRInputDevice.Handedness.Left ? leftSteamDeviceIndex : rightSteamDeviceIndex;
                    steamDeviceIndex = steamDeviceIndices[(int)hand];
                }

                isActive = true;

                int deviceIndex = hand == VRInputDevice.Handedness.Left ? 3 : 4; // TODO change 3 and 4 based on virtual devices defined in InputDeviceManager (using actual hardware available)
                SendButtonEvents(steamDeviceIndex, deviceIndex);
                SendAxisEvents(steamDeviceIndex, deviceIndex);
                SendTrackingEvents(steamDeviceIndex, deviceIndex, poses);
            }

            if (active != isActive)
            {
                active = isActive;
            }
        }
        bool GetAxis(VRInputDevice.Handedness hand, VRInputDevice.VRControl axis, out float value)
        {
            switch (axis)
            {
            case VRInputDevice.VRControl.Trigger1:
                if (hand == VRInputDevice.Handedness.Left)
                {
                    value = UnityEngine.Input.GetAxis("XRI_Left_Trigger");
                }
                else
                {
                    value = UnityEngine.Input.GetAxis("XRI_Right_Trigger");
                }
                return(true);

            case VRInputDevice.VRControl.Trigger2:
                if (hand == VRInputDevice.Handedness.Left)
                {
                    value = UnityEngine.Input.GetAxis("XRI_Left_Grip");
                }
                else
                {
                    value = UnityEngine.Input.GetAxis("XRI_Right_Grip");
                }
                return(true);

            case VRInputDevice.VRControl.LeftStickX:
                if (hand == VRInputDevice.Handedness.Left)
                {
                    value = UnityEngine.Input.GetAxis("XRI_Left_Primary2DAxis_Horizontal");
                }
                else
                {
                    value = UnityEngine.Input.GetAxis("XRI_Right_Primary2DAxis_Horizontal");
                }
                return(true);

            case VRInputDevice.VRControl.LeftStickY:
                if (hand == VRInputDevice.Handedness.Left)
                {
                    value = -1f * UnityEngine.Input.GetAxis("XRI_Left_Primary2DAxis_Vertical");
                }
                else
                {
                    value = -1f * UnityEngine.Input.GetAxis("XRI_Right_Primary2DAxis_Vertical");
                }
                return(true);
            }

            value = 0f;
            return(false);
        }
示例#6
0
    public void Update()
    {
        active = false;
        TrackedDevicePose_t[] poses = null;
        var compositor = OpenVR.Compositor;

        if (compositor != null)
        {
            var render = SteamVR_Render.instance;
            compositor.GetLastPoses(render.poses, render.gamePoses);
            poses = render.poses;
        }

        for (VRInputDevice.Handedness hand = VRInputDevice.Handedness.Left; (int)hand <= (int)VRInputDevice.Handedness.Right; hand++)
        {
            var steamDeviceIndex = steamDeviceIndices[(int)hand];

            if (steamDeviceIndex == -1)
            {
                steamDeviceIndex = SteamVR_Controller.GetDeviceIndex(hand == VRInputDevice.Handedness.Left
                                         ? SteamVR_Controller.DeviceRelation.Leftmost
                                         : SteamVR_Controller.DeviceRelation.Rightmost);

                if (steamDeviceIndex == -1)
                {
                    continue;
                }

                if (hand == VRInputDevice.Handedness.Left)
                {
                    steamDeviceIndices[(int)hand] = steamDeviceIndex;
                }
                else if (steamDeviceIndex != steamDeviceIndices[(int)VRInputDevice.Handedness.Left])                 // Do not assign device to right hand if it is same device as left hand
                {
                    steamDeviceIndices[(int)hand] = steamDeviceIndex;
                }
                else
                {
                    continue;
                }
            }
            active = true;


            int deviceIndex = hand == VRInputDevice.Handedness.Left ? 3 : 4;             // TODO change 3 and 4 based on virtual devices defined in InputDeviceManager (using actual hardware available)
            SendButtonEvents(steamDeviceIndex, deviceIndex);
            SendAxisEvents(steamDeviceIndex, deviceIndex);
            SendTrackingEvents(steamDeviceIndex, deviceIndex, poses);
        }
    }
示例#7
0
        public void Update()
        {
            var isActive = false;

            TrackedDevicePose_t[] poses = null;
            var compositor = OpenVR.Compositor;

            if (compositor != null)
            {
                var render = SteamVR_Render.instance;
                compositor.GetLastPoses(render.poses, render.gamePoses);
                poses = render.poses;
            }

            var leftSteamDeviceIndex  = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost);
            var rightSteamDeviceIndex = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost);

            if (leftSteamDeviceIndex == -1 || rightSteamDeviceIndex == -1 || leftSteamDeviceIndex == rightSteamDeviceIndex)
            {
                return;
            }

            for (VRInputDevice.Handedness hand = VRInputDevice.Handedness.Left; (int)hand <= (int)VRInputDevice.Handedness.Right; hand++)
            {
                var steamDeviceIndex = steamDeviceIndices[(int)hand];

                if (steamDeviceIndex == -1)
                {
                    steamDeviceIndices[(int)hand] = hand == VRInputDevice.Handedness.Left ? leftSteamDeviceIndex : rightSteamDeviceIndex;
                    steamDeviceIndex = steamDeviceIndices[(int)hand];
                }

                isActive = true;

                int deviceIndex = hand == VRInputDevice.Handedness.Left ? 3 : 4;                 // TODO change 3 and 4 based on virtual devices defined in InputDeviceManager (using actual hardware available)
                SendButtonEvents(steamDeviceIndex, deviceIndex);
                SendAxisEvents(steamDeviceIndex, deviceIndex);
                SendTrackingEvents(steamDeviceIndex, deviceIndex, poses);
            }

            if (active != isActive)
            {
                active = isActive;
            }
        }
        void SendButtonEvents(VRInputDevice.Handedness hand, int deviceIndex)
        {
            foreach (VRInputDevice.VRControl button in k_Buttons)
            {
                var axis = GetButtonAxis(hand, button);

                bool isDown = UnityEngine.Input.GetButtonDown(axis);
                bool isUp   = UnityEngine.Input.GetButtonUp(axis);

                if (isDown || isUp)
                {
                    var inputEvent = InputSystem.CreateEvent <GenericControlEvent>();
                    inputEvent.deviceType   = typeof(VRInputDevice);
                    inputEvent.deviceIndex  = deviceIndex;
                    inputEvent.controlIndex = (int)button;
                    inputEvent.value        = isDown ? 1.0f : 0.0f;

                    InputSystem.QueueEvent(inputEvent);
                }
            }
        }
示例#9
0
        protected override string GetButtonAxis(VRInputDevice.Handedness hand, VRInputDevice.VRControl button)
        {
            // For some reason primary/secondary are swapped in OpenVR
            switch (button)
            {
            case VRInputDevice.VRControl.Action1:
                if (hand == VRInputDevice.Handedness.Left)
                {
                    return("XRI_Left_SecondaryButton");
                }
                else
                {
                    return("XRI_Right_SecondaryButton");
                }

            case VRInputDevice.VRControl.Action2:
                if (hand == VRInputDevice.Handedness.Left)
                {
                    return("XRI_Left_PrimaryButton");
                }
                else
                {
                    return("XRI_Right_PrimaryButton");
                }

            case VRInputDevice.VRControl.LeftStickButton:
                if (hand == VRInputDevice.Handedness.Left)
                {
                    return("XRI_Left_Primary2DAxisClick");
                }
                else
                {
                    return("XRI_Right_Primary2DAxisClick");
                }
            }

            // Not all buttons are currently mapped
            return(null);
        }
示例#10
0
        protected virtual string GetButtonAxis(VRInputDevice.Handedness hand, VRInputDevice.VRControl button)
        {
            switch (button)
            {
            case VRInputDevice.VRControl.Action1:
                if (hand == VRInputDevice.Handedness.Left)
                {
                    return("XRI_Left_PrimaryButton");
                }
                else
                {
                    return("XRI_Right_PrimaryButton");
                }

            case VRInputDevice.VRControl.Action2:
                if (hand == VRInputDevice.Handedness.Left)
                {
                    return("XRI_Left_SecondaryButton");
                }
                else
                {
                    return("XRI_Right_SecondaryButton");
                }

            case VRInputDevice.VRControl.LeftStickButton:
                if (hand == VRInputDevice.Handedness.Left)
                {
                    return("XRI_Left_Primary2DAxisClick");
                }
                else
                {
                    return("XRI_Right_Primary2DAxisClick");
                }
            }

            // Not all buttons are currently mapped
            return(null);
        }
示例#11
0
        void SendTrackingEvents(VRInputDevice.Handedness hand, int deviceIndex)
        {
#pragma warning disable 618
            var node          = hand == VRInputDevice.Handedness.Left ? XRNode.LeftHand : XRNode.RightHand;
            var localPosition = InputTracking.GetLocalPosition(node);
            var localRotation = InputTracking.GetLocalRotation(node);
#pragma warning restore 618

            if (localPosition == m_LastPositionValues[(int)hand] && localRotation == m_LastRotationValues[(int)hand])
            {
                return;
            }

            var inputEvent = InputSystem.CreateEvent <VREvent>();
            inputEvent.deviceType    = typeof(VRInputDevice);
            inputEvent.deviceIndex   = deviceIndex;
            inputEvent.localPosition = localPosition;
            inputEvent.localRotation = localRotation;

            m_LastPositionValues[(int)hand] = inputEvent.localPosition;
            m_LastRotationValues[(int)hand] = inputEvent.localRotation;

            InputSystem.QueueEvent(inputEvent);
        }