You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Windows Mixed Reality检测HP Reverb G2佩戴状态失败求助

问题

使用Unity + Mixed Reality Toolkit开发时,通过Windows Mixed Reality无法检测HP Reverb G2的佩戴状态,但SteamVR可以正常检测。目标是不依赖SteamVR实现HMD佩戴状态检测。

已尝试的无效代码
public static bool IsHMDMounted()
{
    if (headDevice == null || headDevice.isValid == false)
    {
        headDevice = InputDevices.GetDeviceAtXRNode(XRNode.Head);
    }
    if (headDevice != null)
    {
        bool presenceFeatureSupported = headDevice.TryGetFeatureValue(CommonUsages.userPresence, out bool userPresent);
        if (headDevice.isValid && presenceFeatureSupported)
        {
            return userPresent;
           
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}
解决方案

方法1:使用MRTK内置用户存在检测API

MRTK提供了封装好的用户状态获取接口,无需手动处理InputDevice:

using Microsoft.MixedReality.Toolkit;
using Microsoft.MixedReality.Toolkit.Input;

public bool IsHMDWorn()
{
    var inputSystem = CoreServices.InputSystem;
    if (inputSystem != null)
    {
        return inputSystem.IsHeadsetPresent && inputSystem.IsUserPresent;
    }
    return false;
}

注:需确保项目中已正确配置MRTK Input System,并启用用户存在检测相关配置项。

方法2:调用Windows原生WinRT API

HP Reverb G2的佩戴状态在Windows Mixed Reality中通过Windows.Perception.People.UserPresence实现,可直接调用原生接口:

using System.Runtime.InteropServices;
using Windows.Perception.People;

public bool CheckHMDUserPresence()
{
    try
    {
        var userPresence = UserPresence.GetDefault();
        return userPresence.IsUserPresent;
    }
    catch
    {
        return false;
    }
}

注:需将Unity Player设置的目标平台改为UWP,启用.NET 4.x及以上脚本运行时,并在Package Manager中添加Windows Runtime支持包。

方法3:使用InputDevice的替代特性

部分设备可能不支持CommonUsages.userPresence,可结合设备追踪状态辅助判断(仅作为补充,无法完全替代佩戴检测):

public static bool IsHMDConnectedAndTracked()
{
    if (headDevice == null || !headDevice.isValid)
    {
        headDevice = InputDevices.GetDeviceAtXRNode(XRNode.Head);
    }
    if (headDevice != null && headDevice.isValid)
    {
        bool isTracked = headDevice.TryGetFeatureValue(CommonUsages.isTracked, out bool tracked) && tracked;
        bool hasPosition = headDevice.TryGetFeatureValue(CommonUsages.position, out _);
        return isTracked && hasPosition;
    }
    return false;
}

额外检查项

  • 确认Unity项目XR Plug-in Management中已启用Windows Mixed Reality插件,配置无误。
  • 检查HP Reverb G2驱动为最新版本,Windows Mixed Reality门户中已启用用户存在检测。
  • 在MRTK Profile设置的Input System Settings里,勾选Enable User Presence。

内容的提问来源于stack exchange,提问作者Alen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 09:00:58