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;
}