问题
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