/// <inheritdoc />
        public override void Update()
        {
            using (UpdatePerfMarker.Auto())
            {
                XRSessionSubsystem sessionSubsystem = SessionSubsystem;
                if (sessionSubsystem == null)
                {
                    return;
                }

                if (sessionSubsystem.trackingState == lastTrackingState && sessionSubsystem.notTrackingReason == lastNotTrackingReason)
                {
                    return;
                }

                // This combination of states is from the Windows XR Plugin docs, describing the combination when positional tracking is inhibited.
                if (sessionSubsystem.trackingState == UnityEngine.XR.ARSubsystems.TrackingState.None && sessionSubsystem.notTrackingReason == NotTrackingReason.Relocalizing)
                {
                    SetTrackingLost(true);
                }
                else
                {
                    SetTrackingLost(false);
                }

                lastTrackingState     = sessionSubsystem.trackingState;
                lastNotTrackingReason = sessionSubsystem.notTrackingReason;
            }
        }
Esempio n. 2
0
    private void Update()
    {
        if (_session != null)
        {
#if UNITY_IOS
            var sessionSubsystem = (ARKitSessionSubsystem)_session.subsystem;
#else
            XRSessionSubsystem sessionSubsystem = null;
#endif
            if (sessionSubsystem == null)
            {
                return;
            }
            if (_status != sessionSubsystem.worldMappingStatus)
            {
                Debug.Log(string.Format("Mapping Status Changed: {0}", sessionSubsystem.worldMappingStatus));
                _status = sessionSubsystem.worldMappingStatus;
                if (_status == ARWorldMappingStatus.Mapped)
                {
                    if (waitCreate != null)
                    {
                        waitCreate.Invoke();
                        waitCreate = null;
                    }
                    else if (waitFound != null)
                    {
                        waitFound.Invoke();
                        waitFound = null;
                    }
                }
            }
        }
    }
Esempio n. 3
0
 /// <summary>
 /// For internal use. Use <c>XRSessionSubsystem.GetAvailabilityAsync</c> instead.
 /// </summary>
 /// <param name="sessionSubsystem">The <c>XRSessionSubsystem</c> which this method extends.</param>
 /// <param name="callback">A callback to invoke when the availability has been determined.</param>
 public static Promise <SessionAvailability> GetAvailabilityAsync(XRSessionSubsystem sessionSubsystem)
 {
     return(ExecuteAsync <SessionAvailability>((context) =>
     {
         Api.ArPresto_checkApkAvailability(OnCheckApkAvailability, context);
     }));
 }
 /// <summary>
 /// Set up an anchor manager.
 /// </summary>
 /// <param name="plugin">The engine interface to update with the current anchor graph.</param>
 private AnchorManagerXR(IPlugin plugin, IHeadPoseTracker headTracker, XRReferencePointSubsystem xrReferencePointManager, XRSessionSubsystem session)
     : base(plugin, headTracker)
 {
     this.xrReferencePointManager = xrReferencePointManager;
     DebugLogSetup($"XR: Created AnchorManager XR, xrMgr={(this.xrReferencePointManager != null ? "good" : "null")}");
     this.sessionSubsystem = session;
 }
Esempio n. 5
0
 /// <summary>
 /// For internal use. Use <c>XRSessionSubsystem.InstallAsync</c> instead.
 /// </summary>
 /// <remarks>
 /// Provides a means to install ARCore if the device supports it but needs an APK update.
 /// </remarks>
 /// <param name="sessionSubsystem">The <c>XRSessionSubsystem</c> which this method extends.</param>
 /// <param name="callback">A callback to invoke when the installation process has completed.</param>
 public static Promise <SessionInstallationStatus> InstallAsync(XRSessionSubsystem sessionSubsystem)
 {
     return(ExecuteAsync <SessionInstallationStatus>((context) =>
     {
         Api.ArPresto_requestApkInstallation(true, OnApkInstallation, context);
     }));
 }
Esempio n. 6
0
        /// <summary>
        /// Detect <see cref="ARWorldMap"/> support. <c>ARWorldMap</c> requires iOS 12 or greater.
        /// See also <see cref="GetARWorldMapAsync(XRSessionSubsystem)"/>.
        /// </summary>
        /// <param name="sessionSubsystem">The <c>XRSessionSubsystem</c> being extended.</param>
        /// <returns><c>true</c> if <c>ARWorldMap</c>s are supported, otherwise <c>false</c>.</returns>
        public static bool WorldMapSupported(this XRSessionSubsystem sessionSubsystem)
        {
            if (sessionSubsystem == null)
            {
                throw new ArgumentNullException("sessionSubsystem");
            }

            return(Api.UnityARKit_worldMapSupported());
        }
Esempio n. 7
0
        /// <summary>
        /// Asynchronously attempts to install AR software on the current device.
        /// </summary>
        /// <remarks>
        /// This platform-agnostic method is typically implemented by a platform-specific package.
        /// </remarks>
        /// <param name="sessionSubsystem">The <c>XRSessionSubsystem</c> to extend.</param>
        /// <returns>A <see cref="Promise{SessionInstallationStatus}"/> which can be used to determine when the
        /// installation completes and retrieve the result.</returns>
        public static Promise <SessionInstallationStatus> InstallAsync(this XRSessionSubsystem sessionSubsystem)
        {
            if (sessionSubsystem == null)
            {
                throw new ArgumentNullException("sessionSubsystem");
            }

            return(s_InstallAsyncDelegate(sessionSubsystem));
        }
Esempio n. 8
0
        /// <summary>
        /// Get the world mapping status. Used to determine the suitability of the current session for
        /// creating an <see cref="ARWorldMap"/>.
        /// </summary>
        /// <param name="sessionSubsystem">The <c>XRSessionSubsystem</c> being extended.</param>
        /// <returns>The <see cref="ARWorldMappingStatus"/> of the session.</returns>
        public static ARWorldMappingStatus GetWorldMappingStatus(this XRSessionSubsystem sessionSubsystem)
        {
            if (sessionSubsystem == null)
            {
                throw new ArgumentNullException("sessionSubsystem");
            }

            return(Api.UnityARKit_getWorldMappingStatus());
        }
Esempio n. 9
0
        /// <summary>
        /// Asynchronously retrieves the <see cref="SessionAvailability"/>. Used to determine whether
        /// the current device supports AR and if the necessary software is installed.
        /// </summary>
        /// <remarks>
        /// This platform-agnostic method is typically implemented by a platform-specific package.
        /// </remarks>
        /// <param name="sessionSubsystem">The <c>XRSessionSubsystem</c> to extend.</param>
        /// <returns>A <see cref="Promise{SessionAvailability}"/> which can be used to determine when the
        /// availability has been determined and retrieve the result.</returns>
        public static Promise <SessionAvailability> GetAvailabilityAsync(this XRSessionSubsystem sessionSubsystem)
        {
            if (sessionSubsystem == null)
            {
                throw new ArgumentNullException("sessionSubsystem");
            }

            return(s_GetAvailabilityAsyncDelegate(sessionSubsystem));
        }
Esempio n. 10
0
        /// <summary>
        /// Retrieves a native <c>IntPtr</c> associated with the <c>XRSessionSubsystem</c>.
        /// Note: This is for advanced usage or access to platform-specific features
        /// not exposed by the existing API.
        /// </summary>
        /// <param name="sessionSubsystem">The <c>XRSessionSubsystem</c> to extend.</param>
        /// <returns>An <c>IntPtr</c> associated with the platform-specific session.</returns>
        public static IntPtr GetNativePtr(this XRSessionSubsystem sessionSubsystem)
        {
            if (sessionSubsystem == null)
            {
                throw new ArgumentNullException("sessionSubsystem");
            }

            return(s_GetNativePtrDelegate(sessionSubsystem));
        }
Esempio n. 11
0
        /// <summary>
        /// Asynchronously create an <see cref="ARWorldMap"/>. An <c>ARWorldMap</c>
        /// represents the state of the session and can be serialized to a byte
        /// array to persist the session data, or send it to another device for
        /// shared AR experiences.
        /// It is a wrapper for <a href="https://developer.apple.com/documentation/arkit/arworldmap">ARKit's ARWorldMap</a>.
        /// See also <see cref="ApplyWorldMap(XRSessionSubsystem, ARWorldMap)"/>.
        /// and <see cref="WorldMapSupported(XRSessionSubsystem)"/>.
        /// </summary>
        /// <param name="sessionSubsystem">The <c>XRSessionSubsystem</c> being extended.</param>
        /// <returns>An <see cref="ARWorldMapRequest"/> which can be used to determine the status
        /// of the request and get the <c>ARWorldMap</c> when complete.</returns>
        public static ARWorldMapRequest GetARWorldMapAsync(this XRSessionSubsystem sessionSubsystem)
        {
            if (sessionSubsystem == null)
            {
                throw new ArgumentNullException("sessionSubsystem");
            }

            var requestId = Api.UnityARKit_createWorldMapRequest();

            return(new ARWorldMapRequest(requestId));
        }
        /// <summary>
        /// For internal use. Use <c>XRSessionSubsystem.GetAvailabilityAsync</c> instead.
        /// </summary>
        /// <param name="sessionSubsystem">The <c>XRSessionSubsystem</c> which this method extends.</param>
        /// <param name="callback">A callback to invoke when the availability has been determined.</param>
        public static Promise <SessionAvailability> GetAvailabilityAsync(XRSessionSubsystem sessionSubsystem)
        {
            var result = Api.UnityARKit_CheckAvailability();
            var retVal = SessionAvailability.None;

            if (result == Api.Availability.Supported)
            {
                retVal = SessionAvailability.Installed | SessionAvailability.Supported;
            }

            return(Promise <SessionAvailability> .CreateResolvedPromise(retVal));
        }
Esempio n. 13
0
        /// <summary>
        /// Asynchronously create an <see cref="ARWorldMap"/>. An <c>ARWorldMap</c>
        /// represents the state of the session and can be serialized to a byte
        /// array to persist the session data, or send it to another device for
        /// shared AR experiences.
        /// It is a wrapper for <a href="https://developer.apple.com/documentation/arkit/arworldmap">ARKit's ARWorldMap</a>.
        /// See also <see cref="ApplyWorldMap(XRSessionSubsystem, ARWorldMap)"/>.
        /// and <see cref="WorldMapSupported(XRSessionSubsystem)"/>.
        ///
        /// If the <see cref="ARWorldMapRequestStatus"/> is <see cref="ARWorldMapRequestStatus.Success"/>, then
        /// the resulting <see cref="ARWorldMap"/> must be disposed to avoid leaking native resources. Otherwise,
        /// the <see cref="ARWorldMap"/> is not valid, and need not be disposed.
        /// </summary>
        /// <param name="sessionSubsystem">The <c>XRSessionSubsystem</c> being extended.</param>
        /// <param name="onComplete">A method to invoke when the world map has either been created, or determined
        /// that it could not be created. Check the value of the <see cref="ARWorldMapRequestStatus"/> parameter
        /// to determine whether the world map was successfully created.</param>
        public static void GetARWorldMapAsync(
            this XRSessionSubsystem sessionSubsystem,
            Action <ARWorldMapRequestStatus, ARWorldMap> onComplete)
        {
            if (sessionSubsystem == null)
            {
                throw new ArgumentNullException("sessionSubsystem");
            }

            var handle  = GCHandle.Alloc(onComplete);
            var context = GCHandle.ToIntPtr(handle);

            Api.UnityARKit_createWorldMapRequestWithCallback(s_OnAsyncWorldMapCompleted, context);
        }
Esempio n. 14
0
 /// <summary>
 /// For internal use. Sets the active subsystem whose extension methods should be used.
 /// </summary>
 /// <param name="sessionSubsystem">The <c>XRSessionSubsystem</c> being extended.</param>
 public static void ActivateExtensions(this XRSessionSubsystem sessionSubsystem)
 {
     if (sessionSubsystem == null)
     {
         SetDefaultDelegates();
     }
     else
     {
         var id = sessionSubsystem.SubsystemDescriptor.id;
         s_InstallAsyncDelegate         = RegistrationHelper.GetValueOrDefault(s_InstallAsyncDelegates, id, DefaultInstallAsync);
         s_GetAvailabilityAsyncDelegate = RegistrationHelper.GetValueOrDefault(s_GetAvailabilityAsyncDelegates, id, DefaultGetAvailabilityAsync);
         s_GetNativePtrDelegate         = RegistrationHelper.GetValueOrDefault(s_GetNativePtrDelegates, id, DefaultGetNativePtr);
     }
 }
        /// <summary>
        /// Set up an anchor manager.
        /// </summary>
        /// <param name="plugin">The engine interface to update with the current anchor graph.</param>
        private AnchorManagerXR(IPlugin plugin, IHeadPoseTracker headTracker, XRAnchorSubsystem xrAnchorManager, XRSessionSubsystem session)
            : base(plugin, headTracker)
        {
            this.xrAnchorManager  = xrAnchorManager;
            this.sessionSubsystem = session;
            Debug.Log($"XR: Created AnchorManager XR, xrMgr={(this.xrAnchorManager != null ? "good" : "null")}");

            Debug.Log($"ActiveLoader name:[{XRGeneralSettings.Instance.Manager.activeLoader.name}] type:[{XRGeneralSettings.Instance.Manager.activeLoader.GetType().FullName}]");

#if WLT_XR_MANAGEMENT_PRESENT
            wmrPersistence    = XRGeneralSettings.Instance.Manager.activeLoader.name.StartsWith("Windows MR");
            openXRPersistence = XRGeneralSettings.Instance.Manager.activeLoader.name.StartsWith("Open XR");
#endif // WLT_XR_MANAGEMENT_PRESENT
            Debug.Log($"XRSDK Persistence: WMR={wmrPersistence} OpenXR={openXRPersistence}");
        }
        public void RunningStateTests()
        {
            XRSessionSubsystem subsystem = CreateTestSessionSubsystem();

            // Initial state is not running
            Assert.That(subsystem.running == false);

            // After start subsystem is running
            subsystem.Start();
            Assert.That(subsystem.running == true);

            // After start subsystem is running
            subsystem.Stop();
            Assert.That(subsystem.running == false);
        }
Esempio n. 17
0
        /// <summary>
        /// Apply an existing <see cref="ARWorldMap"/> to the session. This will attempt
        /// to relocalize the current session to the given <paramref name="worldMap"/>.
        /// If relocalization is successful, the stored planes & reference points from
        /// the <paramref name="worldMap"/> will be added to the current session.
        /// This is equivalent to setting the <a href="https://developer.apple.com/documentation/arkit/arworldtrackingconfiguration/2968180-initialworldmap">initialWorldMap</a>
        /// property on the session's <a href="https://developer.apple.com/documentation/arkit/arworldtrackingconfiguration">ARWorldTrackingConfiguration</a>.
        /// </summary>
        /// <param name="sessionSubsystem">The <c>XRSessionSubsystem</c> being extended.</param>
        /// <param name="worldMap">An <see cref="ARWorldMap"/> with which to relocalize the session.</param>
        public static void ApplyWorldMap(
            this XRSessionSubsystem sessionSubsystem,
            ARWorldMap worldMap)
        {
            if (sessionSubsystem == null)
            {
                throw new ArgumentNullException("sessionSubsystem");
            }

            if (worldMap.nativeHandle == ARWorldMap.k_InvalidHandle)
            {
                throw new InvalidOperationException("ARWorldMap has been disposed.");
            }

            Api.UnityARKit_applyWorldMap(worldMap.nativeHandle);
        }
Esempio n. 18
0
        static Promise <T> ExecuteAsync <T>(this XRSessionSubsystem sessionSubsystem,
                                            Dictionary <string, AsyncDelegate <T> > delegates, T defaultValue = default(T))
        {
            if (sessionSubsystem == null)
            {
                throw new ArgumentNullException("sessionSubsystem");
            }

            AsyncDelegate <T> asyncDelegate;

            if (delegates.TryGetValue(sessionSubsystem.SubsystemDescriptor.id, out asyncDelegate))
            {
                return(asyncDelegate(sessionSubsystem));
            }
            else
            {
                return(Promise <T> .CreateResolvedPromise(defaultValue));
            }
        }
Esempio n. 19
0
        private void Initialize()
        {
            if (this.isInitialized)
            {
                return;
            }

            if (!UnityXRMockActivator.Active)
            {
                if (originalDescriptor == null)
                {
                    originalDescriptor = GetSubsystemDescriptor();
                }

                this.wrappedSubsystem = originalDescriptor?.Create();
            }

            this.isInitialized = true;
        }
    private void Update()
    {
#if UNITY_IOS
        var sessionSubsystem = (ARKitSessionSubsystem)m_session.subsystem;
#else
        XRSessionSubsystem sessionSubsystem = null;
#endif
        if (sessionSubsystem == null)
        {
            return;
        }
        if (!m_isSessionSend)
        {
            IntPtr session = sessionSubsystem.nativePtr;
            #if UNITY_IOS && !UNITY_EDITOR
            _SetUnityARSession(session);
            #endif
            m_isSessionSend = true;
        }
    }
    void Update()
    {
        if (supported)
        {
            SetActive(errorText, false);
            SetActive(saveButton, true);
            SetActive(loadButton, true);
            SetActive(mappingStatusText, true);
        }
        else
        {
            SetActive(errorText, true);
            SetActive(saveButton, false);
            SetActive(loadButton, false);
            SetActive(mappingStatusText, false);
        }

#if UNITY_IOS
        var sessionSubsystem = (ARKitSessionSubsystem)m_ARSession.subsystem;
#else
        XRSessionSubsystem sessionSubsystem = null;
#endif
        if (sessionSubsystem == null)
        {
            return;
        }

        var    numLogsToShow = 20;
        string msg           = "";
        for (int i = Mathf.Max(0, m_LogMessages.Count - numLogsToShow); i < m_LogMessages.Count; ++i)
        {
            msg += m_LogMessages[i];
            msg += "\n";
        }
        SetText(logText, msg);

#if UNITY_IOS
        SetText(mappingStatusText, string.Format("Mapping Status: {0}", sessionSubsystem.worldMappingStatus));
#endif
    }
        /// <summary>
        /// Find and return the correct XRSessionSubsystem.
        /// </summary>
        /// <returns>The XRSessionSubsystem.</returns>
        /// <remarks>
        /// See remarks in <see cref="FindReferencePointManager"/> above.
        /// </remarks>
        private static XRSessionSubsystem FindSessionSubsystem()
        {
            List <XRSessionSubsystem> sessionSubsystems = new List <XRSessionSubsystem>();

            SubsystemManager.GetInstances(sessionSubsystems);
            DebugLogSetup($"Found {sessionSubsystems.Count} session subsystems");
            XRSessionSubsystem activeSession = null;
            int numFound = 0;

            foreach (var session in sessionSubsystems)
            {
                if (session.running)
                {
                    DebugLogSetup($"Found active session subsystem");
                    activeSession = session;
                    ++numFound;
                }
            }
            if (activeSession == null)
            {
                DebugLogSetup($"Found no active session subsystem, will try starting one.");
                foreach (var session in sessionSubsystems)
                {
                    session.Start();
                    if (session.running)
                    {
                        activeSession = session;
                        ++numFound;
                        DebugLogSetup($"Start changed session [{session.SubsystemDescriptor.id}] to running.");
                    }
                }
            }
            if (numFound != 1)
            {
                Debug.LogError($"Found {numFound} active session subsystems, expected exactly one.");
            }
            return(activeSession);
        }
Esempio n. 23
0
 /// <summary>
 /// For internal use. Use <c>XRSessionSubsystem.GetNativePtr</c> instead.
 /// </summary>
 /// <param name="sessionSubsystem">The <c>XRSessionSubsystem</c> which this method extends.</param>
 /// <returns>An <c>IntPtr</c> associated with the <paramref name="sessionSubsystem"/>.</returns>
 public static IntPtr GetNativePtr(XRSessionSubsystem sessionSubsystem)
 {
     return(Api.UnityARCore_getNativeSessionPtr());
 }
Esempio n. 24
0
 static Promise <SessionAvailability> DefaultGetAvailabilityAsync(this XRSessionSubsystem sessionSubsystem)
 {
     return(Promise <SessionAvailability> .CreateResolvedPromise(
                SessionAvailability.Supported | SessionAvailability.Installed));
 }
Esempio n. 25
0
 /// <summary>
 /// Asynchronously retrieves the <see cref="SessionAvailability"/>. Used to determine whether
 /// the current device supports AR and if the necessary software is installed.
 /// </summary>
 /// <remarks>
 /// This platform-agnostic method is typically implemented by a platform-specific package.
 /// </remarks>
 /// <param name="sessionSubsystem">The <c>XRSessionSubsystem</c> to extend.</param>
 /// <returns>A <see cref="Promise{SessionAvailability}"/> which can be used to determine when the
 /// availability has been determined and retrieve the result.</returns>
 public static Promise <SessionAvailability> GetAvailabilityAsync(this XRSessionSubsystem sessionSubsystem)
 {
     return(ExecuteAsync(sessionSubsystem, s_GetAvailabilityAsyncDelegates,
                         SessionAvailability.Supported | SessionAvailability.Installed));
 }
Esempio n. 26
0
 /// <summary>
 /// Asynchronously attempts to install AR software on the current device.
 /// </summary>
 /// <remarks>
 /// This platform-agnostic method is typically implemented by a platform-specific package.
 /// </remarks>
 /// <param name="sessionSubsystem">The <c>XRSessionSubsystem</c> to extend.</param>
 /// <returns>A <see cref="Promise{SessionInstallationStatus}"/> which can be used to determine when the
 /// installation completes and retrieve the result.</returns>
 public static Promise <SessionInstallationStatus> InstallAsync(this XRSessionSubsystem sessionSubsystem)
 {
     return(ExecuteAsync(sessionSubsystem, s_InstallAsyncDelegates,
                         SessionInstallationStatus.ErrorInstallNotSupported));
 }
Esempio n. 27
0
 static Promise <SessionInstallationStatus> DefaultInstallAsync(this XRSessionSubsystem sessionSubsystem)
 {
     return(Promise <SessionInstallationStatus> .CreateResolvedPromise(
                SessionInstallationStatus.ErrorInstallNotSupported));
 }
Esempio n. 28
0
 static IntPtr DefaultGetNativePtr(XRSessionSubsystem sessionSubsystem)
 {
     return(IntPtr.Zero);
 }