コード例 #1
0
    public void VerifyXRDevice_userPresence_isPresent()
    {
        XRGeneralSettings xrGeneralSettings = XRGeneralSettings.Instance;
        XRInputSubsystem  inputs            = xrGeneralSettings.Manager.activeLoader.GetLoadedSubsystem <XRInputSubsystem>();
        var expUserPresenceState            = UserPresenceState.Present;

        var mockHmd = "MockHMD";

        if (Settings.EnabledXrTarget == mockHmd || Application.isEditor)
        {
            var reasonString = Settings.EnabledXrTarget == mockHmd ? $"EnabledXrTarget == {mockHmd}" : "Test is running in the Editor";

            Assert.Ignore("{0}: UserPresenceState.Present will always be false. Ignoring", reasonString);
        }
        else
        {
            List <InputDevice> devices = new List <InputDevice>();
            var userPresenceState      = UserPresenceState.Unknown;
            inputs.TryGetInputDevices(devices);
            foreach (var device in devices)
            {
                if ((device.characteristics & InputDeviceCharacteristics.HeadMounted) == InputDeviceCharacteristics.HeadMounted)
                {
                    var userPresence = new InputFeatureUsage <bool>("UserPresence");
                    if (device.TryGetFeatureValue(userPresence, out bool value) == true)
                    {
                        userPresenceState = value == true ? UserPresenceState.Present : UserPresenceState.NotPresent;
                    }
                    else if (userPresenceState != UserPresenceState.Present)
                    {
                        userPresenceState = UserPresenceState.Unsupported;
                    }
                }
            }
            Assert.AreEqual(userPresenceState, expUserPresenceState, string.Format("Not mobile platform. Expected userPresenceState to be {0}, but is {1}.", expUserPresenceState, userPresenceState));
        }
    }