OpenVRLoader 与UnityXR Interaction ToolKit不兼容

本文探讨了在Unity游戏中遇到的OpenVRLoader与UnityXR Interaction Toolkit不兼容的问题,详细描述了问题的现象,包括无法通过Openvr_xr_plugin获取设备输入输出,以及即使同时开启Openxr和OpenVRLoader也无效。为了解决这个问题,提出了需要修改com.unity.xr.interaction.toolkit插件代码,并介绍了具体步骤,如重新导入插件,安装SteamVR,添加到控制器插件中,并调整InputDeviceWrapper和InputHelper。此外,还建议自行研究SteamVR控制器的设置。
摘要由CSDN通过智能技术生成

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

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

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

 

通过再次导入插件。

4、安装SteamVR

 

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

 

MODIFIED BY TONY!

using System;
using System.Collections.Generic;

#if UNITY_STANDALONE
using Valve.VR;
#endif

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

        /// <summary>
        /// Node we must provide input from
        /// </summary>
        private XRNode m_deviceNode;

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

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="deviceNode">Device from which take the input</param>
        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";
        }

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

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

        /// <summary>
        ///   <para>Read Only. The InputDeviceRole of the device in the XR system. This is a platform provided description of how the device is used.</para>
        /// </summary>
        [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;
            }
        }

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

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

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

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

        /// <summary>
        ///   <para>Sends a raw buffer of haptic data to the device.</para>
        /// </summary>
        /// <param name="channel">The channel to receive the data.</param>
        /// <param name="buffer">A raw byte buffer that contains the haptic data to send to the device.</param>
        /// <returns>
        ///   <para>Returns true if successful. Returns false otherwise.</para>
        /// </returns>
        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);
        }

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

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

        public bool TryGetFeatureValue(InputFeatureUsage<bool> 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;
                }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

虾米神探

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值