コード例 #1
0
        XRInputSubsystem GetActiveSubsystemInstance()
        {
            XRInputSubsystem activeSubsystem = null;

#if USE_XR_MANAGEMENT
            // If the XR management package has been included, query the currently
            // active loader for the created subsystem, if one exists.
            if (XRGeneralSettings.Instance != null && XRGeneralSettings.Instance.Manager != null)
            {
                XRLoader loader = XRGeneralSettings.Instance.Manager.activeLoader;
                if (loader != null)
                {
                    activeSubsystem = loader.GetLoadedSubsystem <XRInputSubsystem>();
                }
            }
#endif
            // If XR management is not used or no loader has been set, check for
            // any active subsystem instances in the SubsystemManager.
            if (activeSubsystem == null)
            {
                List <XRInputSubsystem> subsystemInstances = new List <XRInputSubsystem>();
                SubsystemManager.GetInstances(subsystemInstances);
                if (subsystemInstances.Count > 0)
                {
                    activeSubsystem = subsystemInstances[0];
                }
            }

            return(activeSubsystem);
        }
コード例 #2
0
ファイル: OVRDisplay.cs プロジェクト: bean710/Yonder
    /// <summary>
    /// Recenters the head pose.
    /// </summary>
    public void RecenterPose()
    {
#if USING_XR_SDK
        XRInputSubsystem currentInputSubsystem = OVRManager.GetCurrentInputSubsystem();
        if (currentInputSubsystem != null)
        {
            currentInputSubsystem.TryRecenter();
        }
#elif !REQUIRES_XR_SDK
#pragma warning disable 618
        InputTracking.Recenter();
#pragma warning restore 618
#endif

        // The current poses are cached for the current frame and won't be updated immediately
        // after UnityEngine.VR.InputTracking.Recenter(). So we need to wait until next frame
        // to trigger the RecenteredPose delegate. The application could expect the correct pose
        // when the RecenteredPose delegate get called.
        recenterRequested           = true;
        recenterRequestedFrameCount = Time.frameCount;

#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
        OVRMixedReality.RecenterPose();
#endif
    }
コード例 #3
0
        void Update()
        {
            XRInputSubsystem subsystem = null;

            SubsystemManager.GetInstances(s_InputSubsystems);
            if (s_InputSubsystems.Count > 0)
            {
                subsystem = s_InputSubsystems[0];
            }

            m_SupportedTrackingOriginModes = subsystem?.GetSupportedTrackingOriginModes() ?? TrackingOriginModeFlags.Unknown;

            if (m_CurrentTrackingOriginMode != m_DesiredTrackingOriginMode & m_DesiredTrackingOriginMode != TrackingOriginModeFlags.Unknown)
            {
                subsystem?.TrySetTrackingOriginMode(m_DesiredTrackingOriginMode);
            }
            m_CurrentTrackingOriginMode = subsystem?.GetTrackingOriginMode() ?? TrackingOriginModeFlags.Unknown;

            if (m_CurrentTrackingOriginModeDisplay != null)
            {
                m_CurrentTrackingOriginModeDisplay.text = m_CurrentTrackingOriginMode.ToString();
            }

            if (m_RecenteredImage != null)
            {
                float lerp = (Time.time - m_LastRecenteredTime) / m_RecenteredColorResetTime;
                lerp = Mathf.Clamp(lerp, 0.0f, 1.0f);
                m_RecenteredImage.color = Color.Lerp(m_RecenteredColor, m_RecenteredOffColor, lerp);
            }
        }
コード例 #4
0
ファイル: WindowsMRInput.cs プロジェクト: Venom50/VRRhythm
        public static void GetCurrentSourceStates(this XRInputSubsystem input, List <System.Object> states)
        {
            if (states == null)
            {
                return;
            }

            states.Clear();
            int count = NativeApi.GetCountOfSourceStates();

            if (count > 0)
            {
                IntPtr[] ptrs = new IntPtr[count];
                NativeApi.GetAllSourceStates(ptrs, count);

                foreach (var ip in ptrs)
                {
                    if (ip != IntPtr.Zero)
                    {
                        states.Add(Marshal.GetObjectForIUnknown(ip));
                    }
                }

                NativeApi.ReleaseAllSourceStates(ptrs, states.Count);
            }
        }
コード例 #5
0
        private static XRInputSubsystem GetXRInputSubsystem()
        {
            XRGeneralSettings xrSettings = XRGeneralSettings.Instance;

            if (xrSettings == null)
            {
                Debug.LogWarning($"GetXRInputSubsystem: XRGeneralSettings is null.");
                return(null);
            }

            XRManagerSettings xrManager = xrSettings.Manager;

            if (xrManager == null)
            {
                Debug.LogWarning($"GetXRInputSubsystem: XRManagerSettings is null.");
                return(null);
            }

            XRLoader xrLoader = xrManager.activeLoader;

            if (xrLoader == null)
            {
                Debug.LogWarning($"GetXRInputSubsystem: XRLoader is null.");
                return(null);
            }

            XRInputSubsystem xrInputSubsystem = xrLoader.GetLoadedSubsystem <XRInputSubsystem>();

            if (xrInputSubsystem == null)
            {
                Debug.LogWarning($"GetXRInputSubsystem: XRInputSubsystem is null.");
                return(null);
            }
            return(xrInputSubsystem);
        }
コード例 #6
0
        void OnDestroy()
        {
            if (m_CleanupSubsystemOnDestroy && subsystem != null)
            {
                subsystem.Destroy();
            }

            subsystem = null;
        }
コード例 #7
0
        void OnEnable()
        {
            subsystem = GetActiveSubsystemInstance();

            if (subsystem != null)
            {
                subsystem.Start();
            }
        }
コード例 #8
0
        public IEnumerator TestInputSubsystem()
        {
            yield return(new WaitForSeconds(1));

            Assert.IsNotNull(ActiveLoader);
            XRInputSubsystem inputSub = ActiveLoader.GetLoadedSubsystem <XRInputSubsystem>();

            Assert.IsNotNull(inputSub);
        }
コード例 #9
0
        void OnDestroy()
        {
            if (subsystem != null)
            {
                subsystem.Destroy();
            }

            subsystem = null;
        }
コード例 #10
0
        void OnEnable()
        {
            if (subsystem == null)
            {
                subsystem = CreateSubsystem();
            }

            if (subsystem != null)
            {
                subsystem.Start();
            }
        }
コード例 #11
0
 void OnDeviceConnected(InputDevice device)
 {
     if (m_XrInputSubsystem == null)
     {
         m_XrInputSubsystem = device.subsystem;
         if (m_XrInputSubsystem != null)
         {
             m_XrInputSubsystem.boundaryChanged += BoundaryChanged;
             BoundaryChanged(m_XrInputSubsystem);
         }
     }
 }
コード例 #12
0
        bool SetupCamera(XRInputSubsystem subsystem)
        {
            if (subsystem == null)
            {
                return(false);
            }

            bool trackingSettingsSet = false;

            float desiredOffset = cameraYOffset;

            if (m_TrackingSpace == TrackingSpaceType.RoomScale)
            {
                // We need to check for Unknown because we may not be in a state where we can read this data yet.
                if ((subsystem.GetSupportedTrackingOriginModes() & (TrackingOriginModeFlags.Floor | TrackingOriginModeFlags.Unknown)) == 0)
                {
                    Debug.LogWarning("XRRig.SetupCamera: Attempting to set the tracking space to Room, but that is not supported by the SDK.");
                    return(true);
                }

                if (subsystem.TrySetTrackingOriginMode(TrackingOriginModeFlags.Floor))
                {
                    desiredOffset       = 0;
                    trackingSettingsSet = true;
                }
            }

            if (m_TrackingSpace == TrackingSpaceType.Stationary)
            {
                // We need to check for Unknown because we may not be in a state where we can read this data yet.
                if ((subsystem.GetSupportedTrackingOriginModes() & (TrackingOriginModeFlags.Device | TrackingOriginModeFlags.Unknown)) == 0)
                {
                    Debug.LogWarning("XRRig.SetupCamera: Attempting to set the tracking space to Stationary, but that is not supported by the SDK.");
                    return(true);
                }

                if (subsystem.TrySetTrackingOriginMode(TrackingOriginModeFlags.Device))
                {
                    trackingSettingsSet = subsystem.TryRecenter();
                }
            }

            if (trackingSettingsSet)
            {
                // Move camera to correct height
                if (m_CameraFloorOffsetObject)
                {
                    m_CameraFloorOffsetObject.transform.localPosition = new Vector3(m_CameraFloorOffsetObject.transform.localPosition.x, desiredOffset, m_CameraFloorOffsetObject.transform.localPosition.z);
                }
            }
            return(trackingSettingsSet);
        }
コード例 #13
0
        public IEnumerator TestFloorTrackingOriginMode()
        {
            yield return(new WaitForSeconds(1));

            XRInputSubsystem inputSub = ActiveLoader.GetLoadedSubsystem <XRInputSubsystem>();

            if (inputSub.GetTrackingOriginMode() == TrackingOriginModeFlags.Floor)
            {
                List <Vector3> boundaryPoints = new List <Vector3>();
                inputSub.TryGetBoundaryPoints(boundaryPoints);
                Assert.IsFalse(boundaryPoints.Count == 0);
            }
        }
コード例 #14
0
        void SetToNextMode(XRInputSubsystem subsystem)
        {
            TrackingOriginModeFlags currentOriginMode = subsystem.GetTrackingOriginMode();

            for (int i = 0; i < s_SupportedTrackingOriginModes.Count; i++)
            {
                if (currentOriginMode == s_SupportedTrackingOriginModes[i])
                {
                    int nextModeIndex = (i + 1) % s_SupportedTrackingOriginModes.Count;
                    subsystem.TrySetTrackingOriginMode(s_SupportedTrackingOriginModes[nextModeIndex]);
                    break;
                }
            }
        }
コード例 #15
0
        void UpdateSupportedTrackingOriginModes(XRInputSubsystem subsystem)
        {
            TrackingOriginModeFlags supportedOriginModes = subsystem.GetSupportedTrackingOriginModes();

            s_SupportedTrackingOriginModes.Clear();
            for (int i = 0; i < 31; i++)
            {
                uint modeToCheck = 1u << i;
                if ((modeToCheck & ((UInt32)supportedOriginModes)) != 0)
                {
                    s_SupportedTrackingOriginModes.Add((TrackingOriginModeFlags)modeToCheck);
                }
            }
        }
    void AddElement(XRInputSubsystem inputSubsystem, int systemNumber)
    {
        if (Mathf.Abs(m_NextPosition.y) > m_ParentRect.rect.height)
        {
            m_ParentRect.sizeDelta = new Vector2(m_ParentRect.sizeDelta.x, m_ParentRect.sizeDelta.y + m_RowSeparation);
        }
        GameObject NewSubsystemUI = Instantiate(uiPrefab, m_ParentRect);

        m_Elements.Add(NewSubsystemUI);
        NewSubsystemUI.transform.localPosition = m_NextPosition;
        NewSubsystemUI.GetComponent <RectTransform>().anchorMin = new Vector2(0.5f, 1f);
        NewSubsystemUI.GetComponent <RectTransform>().anchorMax = new Vector2(0.5f, 1f);
        m_NextPosition = new Vector3(0, m_NextPosition.y - m_RowSeparation, 0);

        NewSubsystemUI.GetComponent <InputSubsystemPanel>().Setup(xrRig, systemNumber, inputSubsystem);
    }
コード例 #17
0
 void Update()
 {
     m_TimeRemainingTillChange -= Time.deltaTime;
     if (m_TimeRemainingTillChange <= 0.0f)
     {
         List <XRInputSubsystem> inputSubsystems = new List <XRInputSubsystem>();
         SubsystemManager.GetInstances(inputSubsystems);
         XRInputSubsystem subsystem = inputSubsystems?[0];
         if (subsystem != null)
         {
             UpdateSupportedTrackingOriginModes(subsystem);
             SetToNextMode(subsystem);
         }
         m_TimeRemainingTillChange += m_ChangeInterval;
     }
 }
コード例 #18
0
 public bool DrawPlayArea(XRInputSubsystem subsystem)
 {
     if (subsystem != null)
     {
         if (subsystem.TryGetBoundaryPoints(boundaryPoints))
         {
             Debug.Log($"Got {boundaryPoints.Count} boundary points");
             if (boundaryPoints.Count > 0)
             {
                 ReadBoundPoints();
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #19
0
        public IEnumerator TestBoundaryIsAtGround()
        {
            yield return(new WaitForSeconds(1));

            XRInputSubsystem inputSub = ActiveLoader.GetLoadedSubsystem <XRInputSubsystem>();

            if (inputSub.GetTrackingOriginMode() == TrackingOriginModeFlags.Floor)
            {
                List <Vector3> boundaryPoints = new List <Vector3>();
                inputSub.TryGetBoundaryPoints(boundaryPoints);
                for (int i = 0; i < boundaryPoints.Count; i++)
                {
                    Assert.That(boundaryPoints[i].y, Is.EqualTo(0.0f).Within(1).Ulps);
                }
            }
        }
コード例 #20
0
        private void ConnectCardboardInputSystem()
        {
            List <XRInputSubsystemDescriptor> inputs = new List <XRInputSubsystemDescriptor>();

            SubsystemManager.GetSubsystemDescriptors(inputs);

            foreach (var d in inputs)
            {
                if (d.id.Equals(inputMatch))
                {
                    XRInputSubsystem inputInst = d.Create();

                    if (inputInst != null)
                    {
                        GCHandle handle = GCHandle.Alloc(inputInst);
                        inputPointer = GCHandle.ToIntPtr(handle);
                    }
                }
            }
        }
コード例 #21
0
ファイル: ARInputManager.cs プロジェクト: raizo2000/0003
        XRInputSubsystem GetActiveSubsystemInstance()
        {
            XRInputSubsystem activeSubsystem = null;

            // Query the currently active loader for the created subsystem, if one exists.
            if (XRGeneralSettings.Instance != null && XRGeneralSettings.Instance.Manager != null)
            {
                XRLoader loader = XRGeneralSettings.Instance.Manager.activeLoader;
                if (loader != null)
                {
                    activeSubsystem = loader.GetLoadedSubsystem <XRInputSubsystem>();
                }
            }

            if (activeSubsystem == null)
            {
                Debug.LogWarning($"No active {typeof(XRInputSubsystem).FullName} is available. Please ensure that a " +
                                 "valid loader configuration exists in the XR project settings.");
            }

            return(activeSubsystem);
        }
コード例 #22
0
        void CreateSubsystemIfNecessary()
        {
            // Use the subsystem that has been instantiated by XR Management
            // if available, otherwise create the subsystem.

            if (subsystem == null)
            {
                subsystem = GetActiveSubsystemInstance();

                // If the subsystem has already been created by XR management, it controls the lifetime
                // of the subsystem.
                if (subsystem != null)
                {
                    m_CleanupSubsystemOnDestroy = false;
                }
            }

            if (subsystem == null)
            {
                subsystem = CreateSubsystem();
            }
        }
コード例 #23
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));
        }
    }
コード例 #24
0
        void BoundaryChanged(XRInputSubsystem inputSubsystem)
        {
            // m_XrInputSubsystem = inputSubsystem;
            // var allPoints = new List<Vector3>();

            // TODO Figure out why this boundary is not correct
            // if (m_XrInputSubsystem.TryGetBoundaryPoints(allPoints))
            // {
            //     m_DefaultBoundary.SetActive(false);
            //     m_BoundaryLineRenderer.enabled = true;
            //     var prevPoint = allPoints[0];
            //     var delta = Vector3.forward;
            //     var prevDelta = Vector3.zero;
            //     m_BoundaryPoints.Clear();
            //     for (var i = 1; i < allPoints.Count; i++)
            //     {
            //         var point = allPoints[i];
            //         delta = prevPoint - point;
            //         if (Vector3.Magnitude(delta) > 0.05f || Vector3.Dot(delta.normalized, prevDelta.normalized) < 0.5f)
            //         {
            //             prevPoint = point;
            //             prevDelta = delta;
            //             m_BoundaryPoints.Add(point);
            //         }
            //
            //     }
            //
            //     m_BoundaryLineRenderer.SetVertexCount(m_BoundaryPoints.Count);
            //     m_BoundaryLineRenderer.SetPositions(m_BoundaryPoints.ToArray());
            // }
            // else
            {
                m_DefaultBoundary.SetActive(true);
                m_BoundaryLineRenderer.enabled = false;
            }
        }
コード例 #25
0
ファイル: WindowsMRInput.cs プロジェクト: Venom50/VRRhythm
 public static NativeTypes.SpatialLocatability GetSpatialLocatability(this XRInputSubsystem input)
 {
     return(Native.GetSpatialLocatability());
 }
コード例 #26
0
 void OnDestroy()
 {
     subsystem = null;
 }
コード例 #27
0
        bool SetupCamera(XRInputSubsystem subsystem)
        {
            if (subsystem == null)
            {
                return(false);
            }

            bool trackingSettingsSet = false;

            float desiredOffset = cameraYOffset;

            var currentMode    = subsystem.GetTrackingOriginMode();
            var supportedModes = subsystem.GetSupportedTrackingOriginModes();
            TrackingOriginModeFlags requestedMode = TrackingOriginModeFlags.Unknown;

            // map between the user requested options, and the actual options.
            if (m_RequestedTrackingMode == UserRequestedTrackingMode.Default)
            {
                requestedMode = currentMode;
            }
            else if (m_RequestedTrackingMode == UserRequestedTrackingMode.Device)
            {
                requestedMode = TrackingOriginModeFlags.Device;
            }
            else if (m_RequestedTrackingMode == UserRequestedTrackingMode.Floor)
            {
                requestedMode = TrackingOriginModeFlags.Floor;
            }
            else
            {
                Debug.LogWarning("Unknown Requested Tracking Mode");
            }

            // now we've mapped em. actually go set em.
            if (requestedMode == TrackingOriginModeFlags.Floor)
            {
                // We need to check for Unknown because we may not be in a state where we can read this data yet.
                if ((supportedModes & (TrackingOriginModeFlags.Floor | TrackingOriginModeFlags.Unknown)) == 0)
                {
                    Debug.LogWarning("CameraOffset.SetupCamera: Attempting to set the tracking space to Floor, but that is not supported by the SDK.");
                    m_TrackingOriginMode = subsystem.GetTrackingOriginMode();
                    return(true);
                }

                if (subsystem.TrySetTrackingOriginMode(requestedMode))
                {
                    desiredOffset       = 0.0f;
                    trackingSettingsSet = true;
                }
            }
            else if (requestedMode == TrackingOriginModeFlags.Device)
            {
                // We need to check for Unknown because we may not be in a state where we can read this data yet.
                if ((supportedModes & (TrackingOriginModeFlags.Device | TrackingOriginModeFlags.Unknown)) == 0)
                {
                    Debug.LogWarning("CameraOffset.SetupCamera: Attempting to set the tracking space to Device, but that is not supported by the SDK.");
                    m_TrackingOriginMode = subsystem.GetTrackingOriginMode();
                    return(true);
                }

                if (subsystem.TrySetTrackingOriginMode(requestedMode))
                {
                    trackingSettingsSet = subsystem.TryRecenter();
                }
            }

            // what did we actually set?
            m_TrackingOriginMode = subsystem.GetTrackingOriginMode();

            if (trackingSettingsSet)
            {
                // Move camera to correct height
                if (m_CameraFloorOffsetObject)
                {
                    m_CameraFloorOffsetObject.transform.localPosition = new Vector3(m_CameraFloorOffsetObject.transform.localPosition.x, desiredOffset, m_CameraFloorOffsetObject.transform.localPosition.z);
                }
            }
            return(trackingSettingsSet);
        }
コード例 #28
0
ファイル: CameraOffset.cs プロジェクト: Metrulizer/Spaceship
 private void OnTrackingOriginUpdated(XRInputSubsystem subsystem) => UpdateTrackingOrigin(subsystem.GetTrackingOriginMode());
コード例 #29
0
ファイル: CameraOffset.cs プロジェクト: Metrulizer/Spaceship
        bool SetupCamera(XRInputSubsystem subsystem)
        {
            if (subsystem == null)
            {
                return(false);
            }

            bool trackingSettingsSet = false;

            var currentMode    = subsystem.GetTrackingOriginMode();
            var supportedModes = subsystem.GetSupportedTrackingOriginModes();
            TrackingOriginModeFlags requestedMode = TrackingOriginModeFlags.Unknown;

            // map between the user requested options, and the actual options.
            if (m_RequestedTrackingMode == UserRequestedTrackingMode.Default)
            {
                requestedMode = currentMode;
            }
            else if (m_RequestedTrackingMode == UserRequestedTrackingMode.Device)
            {
                requestedMode = TrackingOriginModeFlags.Device;
            }
            else if (m_RequestedTrackingMode == UserRequestedTrackingMode.Floor)
            {
                requestedMode = TrackingOriginModeFlags.Floor;
            }
            else
            {
                Debug.LogWarning("Unknown Requested Tracking Mode");
            }

            // now we've mapped em. actually go set em.
            if (requestedMode == TrackingOriginModeFlags.Floor)
            {
                // We need to check for Unknown because we may not be in a state where we can read this data yet.
                if ((supportedModes & (TrackingOriginModeFlags.Floor | TrackingOriginModeFlags.Unknown)) == 0)
                {
                    Debug.LogWarning("CameraOffset.SetupCamera: Attempting to set the tracking space to Floor, but that is not supported by the SDK.");
                }
                else
                {
                    trackingSettingsSet = subsystem.TrySetTrackingOriginMode(requestedMode);
                }
            }
            else if (requestedMode == TrackingOriginModeFlags.Device)
            {
                // We need to check for Unknown because we may not be in a state where we can read this data yet.
                if ((supportedModes & (TrackingOriginModeFlags.Device | TrackingOriginModeFlags.Unknown)) == 0)
                {
                    Debug.LogWarning("CameraOffset.SetupCamera: Attempting to set the tracking space to Device, but that is not supported by the SDK.");
                }
                else
                {
                    trackingSettingsSet = subsystem.TrySetTrackingOriginMode(requestedMode) && subsystem.TryRecenter();
                }
            }

            if (trackingSettingsSet)
            {
                UpdateTrackingOrigin(subsystem.GetTrackingOriginMode());
            }

            return(trackingSettingsSet);
        }
コード例 #30
0
 private void TrackingOriginUpdated(XRInputSubsystem obj)
 {
     m_LastRecenteredTime = Time.time;
 }