How do you detect whether your Mixed Reality app is running on HoloLens 1, HoloLens 2 or an immersive headset?

和自甴很熟 提交于 2020-05-15 07:54:16

问题


Mixed Reality apps can soon run on three kinds of devices: HoloLens 1, Hololens 2 and Immersive (VR) headsets. Some behavior will likely be different depending on the type of device you run the app on. How can I ask the SDK what kind of device my app is running currently on?


回答1:


If you are using MRTK (I noticed you might based on your tag), then the best way to do this is by using platform capabilities utility, since that will work as new devices come out, and across platforms. For example, instead of checking "am on on HoloLens 2" you can check "does my device support articulated hands?". That will then work on other platforms that support articulated hands. For an example, chekc out MixedRealityToolkit.Examples/Demos/Utilities/Scenes/MixedRealityCapabilityDemo.unity in MRTK examples.

If you need a temporary solution for now to differentiate WMR from HL1 from HL2, you can use the following code. Note it's windows-only:

using Windows.Security.ExchangeActiveSyncProvisioning;

EasClientDeviceInformation CurrentInfo = new EasClientDeviceInformation();
string sku = CurrentInfo.SystemSku;

HoloLens 1, HoloLens 2, and Immersive headsets should all return different strings.




回答2:


HolographicDisplay.GetDefault().IsOpaque is true for Immersive VR headsets and false for AR devices like HoloLens.

For HoloLens you don't need to detect a precise device family. Instead you should check the feature support via Universal Contract Version like

bool checkUniversalApiContract(int contractNumber)
{
    return winrt::Windows::Foundation::Metadata::ApiInformation::IsApiContractPresent(L"Windows.Foundation.UniversalApiContract", contractNumber);
}

bool supportsHandTracking = checkUniversalApiContract(8);




回答3:


To check whether it is opaque (VR) or not (AR):

#if UNITY_2017_2_OR_NEWER
            bool isOpaque = UnityEngine.XR.WSA.HolographicSettings.IsDisplayOpaque;
#else
            bool isOpaque = UnityEngine.VR.VRDevice.isPresent;
#endif

To check whether it is HL1 or HL2, this is a simple solution, not requiring other dlls:

#if UNITY_WSA || UNITY_WSA_10_0
            // Get vertical field of view in degrees
            // HL1  == 17.5, HL2 == 29
            bool isHL1  = (Camera.main.fieldOfView < 23f);
#endif


来源:https://stackoverflow.com/questions/57552637/how-do-you-detect-whether-your-mixed-reality-app-is-running-on-hololens-1-holol

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!