OpenVRLoader 与UnityXR Interaction ToolKit不兼容

1、游戏的VR设备监听与输入都是基于UnityXR,但是当接入OpenVRLoader 时无法正常通过Openvr_xr_plugin去获取设备的输入输出。

2、Openxr 和OpenVRLoader同时打开也还是会没有输入信息。

OpenVRLoader 与UnityXR Interaction ToolKit不兼容_第1张图片

3、我们需要修改com.unity.xr.interaction.toolkit插件代码,不能直接用packmanage的将插件从缓存中拷贝出来。

 OpenVRLoader 与UnityXR Interaction ToolKit不兼容_第2张图片OpenVRLoader 与UnityXR Interaction ToolKit不兼容_第3张图片

通过再次导入插件。

4、安装SteamVR

OpenVRLoader 与UnityXR Interaction ToolKit不兼容_第4张图片

OpenVRLoader 与UnityXR Interaction ToolKit不兼容_第5张图片

 

OpenVRLoader 与UnityXR Interaction ToolKit不兼容_第6张图片

添加到控制插件中。 并且增加一个InputDeviceWrapper

 

MODIFIED BY TONY!

using System;
using System.Collections.Generic;

#if UNITY_STANDALONE
using Valve.VR;
#endif

namespace UnityEngine.XR.Interaction.Toolkit
{
    /// 
    /// Wraps an input device for the XR Interaction toolkit to add support for SteamVR Input System
    /// 
    public struct InputDeviceWrapper
    {
        /// 
        /// The wrapped Input Device. We'll take positions and rotations from it in any case.
        /// It will also provide inputs with non-SteamVR headsets
        /// 
        private InputDevice m_inputDevice;

        /// 
        /// Node we must provide input from
        /// 
        private XRNode m_deviceNode;

        /// 
        /// True if there is steamvr activated, false otherwise
        /// 
        private bool m_isSteamVR;

        /// 
        /// Constructor
        /// 
        /// Device from which take the input
        internal InputDeviceWrapper(XRNode deviceNode)
        {
            m_inputDevice = InputDevices.GetDeviceAtXRNode(deviceNode);
            this.m_deviceNode = deviceNode;
            this.m_isSteamVR = m_inputDevice.subsystem != null && m_inputDevice.subsystem.SubsystemDescriptor.id == "OpenVR Input";
        }

        /// 
        ///   Read Only. True if the device is currently a valid input device; otherwise false.
        /// 
        public bool isValid
        {
            get
            {
                return m_inputDevice.isValid;
            }
        }

        /// 
        ///   Read Only. The name of the device in the XR system. This is a platform provided unique identifier for the device.
        /// 
        public string name
        {
            get
            {
                return m_inputDevice.name;
            }
        }

        /// 
        ///   Read Only. The InputDeviceRole of the device in the XR system. This is a platform provided description of how the device is used.
        /// 
        [Obsolete("This API has been marked as deprecated and will be removed in future versions. Please use InputDevice.characteristics instead.")]
        public InputDeviceRole role
        {
            get
            {
                return m_inputDevice.role;
            }
        }

        /// 
        ///   The manufacturer of the connected Input Device.
        /// 
        public string manufacturer
        {
            get
            {
                return m_inputDevice.manufacturer;
            }
        }

        /// 
        ///   The serial number of the connected Input Device.  Blank if no serial number is available.
        /// 
        public string serialNumber
        {
            get
            {
                return m_inputDevice.serialNumber;
            }
        }

        /// 
        ///   Read Only. A bitmask of enumerated flags describing the characteristics of this InputDevice.
        /// 
        public InputDeviceCharacteristics characteristics
        {
            get
            {
                return m_inputDevice.characteristics;
            }
        }

        /// 
        ///   Sends a haptic impulse to a device.
        /// 
        /// The channel to receive the impulse.
        /// The normalized (0.0 to 1.0) amplitude value of the haptic impulse to play on the device.
        /// The duration in seconds that the haptic impulse will play. Only supported on Oculus.
        /// 
        ///   Returns true if successful. Returns false otherwise.
        /// 
        public bool SendHapticImpulse(uint channel, float amplitude, float duration = 1f)
        {
            return m_inputDevice.SendHapticImpulse(channel, amplitude, duration);
        }

        /// 
        ///   Sends a raw buffer of haptic data to the device.
        /// 
        /// The channel to receive the data.
        /// A raw byte buffer that contains the haptic data to send to the device.
        /// 
        ///   Returns true if successful. Returns false otherwise.
        /// 
        public bool SendHapticBuffer(uint channel, byte[] buffer)
        {
            return m_inputDevice.SendHapticBuffer(channel, buffer);
        }

        public bool TryGetHapticCapabilities(out HapticCapabilities capabilities)
        {
            return m_inputDevice.TryGetHapticCapabilities(out capabilities);
        }

        /// 
        ///   Stop all haptic playback for a device.
        /// 
        public void StopHaptics()
        {
            m_inputDevice.StopHaptics();
        }

        public bool TryGetFeatureUsages(List featureUsages)
        {
            return m_inputDevice.TryGetFeatureUsages(featureUsages);
        }

        public bool TryGetFeatureValue(InputFeatureUsage usage, out bool value)
        {
#if UNITY_STANDALONE
            if (m_isSteamVR && m_deviceNode.IsHands())
            {
                if (usage == CommonUsages.triggerButton)
                {
                    value = SteamVR_Actions._default.GrabPinch[m_deviceNode.ToSteamVrSource()].state;

                    return true;
                }
                else if (usage == CommonUsages.gripButton)
                {
                    value = SteamVR_Actions._default.GrabGrip[m_deviceNode.ToSteamVrSource()].state;

                    return true;
                }
                else if(usage == CommonUsages.primaryButton)
                {
                    value = SteamVR_Actions._default.PrimaryButton[m_deviceNode.ToSteamVrSource()].state;

                    return true;
                }
                else if(usage == CommonU

你可能感兴趣的:(unity)