Ejemplo n.º 1
0
        /// <summary>
        /// Iterate over the configured list of loaders and attempt to initialize each one. The first one
        /// that succeeds is set as the active loader and initialization immediately terminates.
        ///
        /// When complete <see cref="isInitializationComplete"> will be set to true. This will mark that it is safe to
        /// call other parts of the API. This does not guarantee that init successfully created a loader. For that
        /// you need to check that ActiveLoader is not null.
        ///
        /// Note that there can only be one active loader. Any attempt to initialize a new active loader with one
        /// already set will cause a warning to be logged and immediate exit of this function.
        /// </summary>
        ///
        /// <returns>Enumerator marking the next spot to continue execution at.</returns>
        public IEnumerator InitializeLoader()
        {
            if (activeLoader != null)
            {
                Debug.LogWarning(
                    "XR Management has already initialized an active loader in this scene." +
                    "Please make sure to stop all subsystems and deinitialize the active loader before initializing a new one.");
                yield break;
            }

            foreach (var loader in loaders)
            {
                if (loader != null)
                {
                    if (loader.Initialize())
                    {
                        activeLoader             = loader;
                        m_InitializationComplete = true;
                        yield break;
                    }
                }

                yield return(null);
            }

            activeLoader = null;
        }
        /// <summary>
        /// Attempts to append the given loader to the list of loaders at the given index.
        /// </summary>
        /// <param name="loader">
        /// The <see cref="XRLoader"/> to be added to this manager's instance of loaders.
        /// </param>
        /// <param name="index">
        /// The index at which the given <see cref="XRLoader"/> should be added. If you set a negative or otherwise
        /// invalid index, the loader will be appended to the end of the list.
        /// </param>
        /// <returns>
        /// <c>true</c> if the loader is not a duplicate and was added to the list successfully, <c>false</c>
        /// otherwise.
        /// </returns>
        /// <remarks>
        /// This method behaves differently in the Editor and during runtime/Play mode. While your app runs in the Editor and not in
        /// Play mode, attempting to add an <see cref="XRLoader"/> will always succeed and register that loader's type
        /// internally. Attempting to add a loader during runtime/Play mode will trigger a check to see whether a loader of
        /// that type was registered. If the check is successful, the loader is added. If not, the loader is not added and the method
        /// returns <c>false</c>.
        /// </remarks>
        public bool TryAddLoader(XRLoader loader, int index = -1)
        {
            if (loader == null || currentLoaders.Contains(loader))
            {
                return(false);
            }

#if UNITY_EDITOR
            if (!EditorApplication.isPlaying && !m_RegisteredLoaders.Contains(loader))
            {
                m_RegisteredLoaders.Add(loader);
            }
#endif
            if (!m_RegisteredLoaders.Contains(loader))
            {
                return(false);
            }

            if (index < 0 || index >= currentLoaders.Count)
            {
                currentLoaders.Add(loader);
            }
            else
            {
                currentLoaders.Insert(index, loader);
            }

            return(true);
        }
Ejemplo n.º 3
0
        internal void InitializeLoaderSync()
        {
            if (activeLoader != null)
            {
                Debug.LogWarning(
                    "XR Management has already initialized an active loader in this scene." +
                    "Please make sure to stop all subsystems and deinitialize the active loader before initializing a new one.");
                return;
            }

            foreach (var loader in loaders)
            {
                if (loader != null)
                {
                    if (loader.Initialize())
                    {
                        activeLoader             = loader;
                        m_InitializationComplete = true;
                        return;
                    }
                }
            }

            activeLoader = null;
        }
Ejemplo n.º 4
0
        private bool CheckLoaderRegistration(XRLoader loader)
        {
#if UNITY_EDITOR
            // Need to check if the application is in play mode, if not then the set of registered loaders is mutable.
            if (!Application.isPlaying)
            {
                return(!m_RegisteredLoaders.Contains(loader));
            }
#endif

            return(m_RegisteredLoaders.Contains(loader) && !currentLoaders.Contains(loader));
        }
Ejemplo n.º 5
0
        private bool CheckGraphicsAPICompatibility(XRLoader loader)
        {
            GraphicsDeviceType        deviceType           = SystemInfo.graphicsDeviceType;
            List <GraphicsDeviceType> supportedDeviceTypes = loader.GetSupportedGraphicsDeviceTypes(false);

            // To help with backward compatibility, if the compatibility list is empty we assume that it does not implement the GetSupportedGraphicsDeviceTypes method
            // Therefore we revert to the previous behavior of building or starting the loader regardless of gfx api settings.
            if (supportedDeviceTypes.Count > 0 && !supportedDeviceTypes.Contains(deviceType))
            {
                Debug.LogWarning(String.Format("The {0} does not support the initialized graphics device, {1}. Please change the preffered Graphics API in PlayerSettings. Attempting to start the next XR loader.", loader.name, deviceType.ToString()));
                return(false);
            }

            return(true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Attempts to remove the first instance of a given loader from the list of loaders.
        /// </summary>
        /// <param name="loader">
        /// The <see cref="XRLoader"/> to be removed from this manager's instance of loaders.
        /// </param>
        /// <returns>
        /// <c>true</c> if the loader was successfully removed from the list, <c>false</c> otherwise.
        /// </returns>
        /// <remarks>
        /// This method behaves differently in the Editor and during runtime/Play mode. During runtime/Play mode, the loader
        /// will be removed with no additional side effects if it is in the list managed by this instance. While in the
        /// Editor and not in Play mode, the loader will be removed if it exists and
        /// it will be unregistered from this instance and any attempts to add it during
        /// runtime/Play mode will fail. You can re-add the loader in the Editor while not in Play mode.
        /// </remarks>
        public bool TryRemoveLoader(XRLoader loader)
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                m_RegisteredLoaders.Remove(loader);
            }
#endif
            if (currentLoaders.Contains(loader))
            {
                return(currentLoaders.Remove(loader));
            }

            return(true);
        }
        /// <summary>
        /// Attempts to remove the first instance of a given loader from the list of loaders.
        /// </summary>
        /// <param name="loader">
        /// The <see cref="XRLoader"/> to be removed from this manager's instance of loaders.
        /// </param>
        /// <returns>
        /// <c>true</c> if the loader was successfully removed from the list, <c>false</c> otherwise.
        /// </returns>
        /// <remarks>
        /// This method behaves differently in the Editor and during runtime/Play mode. During runtime/Play mode, the loader
        /// will be removed with no additional side effects if it is in the list managed by this instance. While in the
        /// Editor and not in Play mode, the loader will be removed if it exists and
        /// it will be unregistered from this instance and any attempts to add it during
        /// runtime/Play mode will fail. You can re-add the loader in the Editor while not in Play mode.
        /// </remarks>
        public bool TryRemoveLoader(XRLoader loader)
        {
            var removedLoader = true;

            if (currentLoaders.Contains(loader))
            {
                removedLoader = currentLoaders.Remove(loader);
            }

#if UNITY_EDITOR
            if (!EditorApplication.isPlaying && !currentLoaders.Contains(loader))
            {
                m_RegisteredLoaders.Remove(loader);
            }
#endif

            return(removedLoader);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// If there is an active loader, this function will deinitialize it and remove the active loader instance from
        /// management. We will automatically call <see cref="StopSubsystems"/> prior to deinitialization to make sure
        /// that things are cleaned up appropriately.
        ///
        /// You must wait for <see cref="isInitializationComplete"> to be set to tru prior to calling this API.
        ///
        /// Upon return <see cref="isInitializationComplete"> will be rest to false;
        /// </summary>
        public void DeinitializeLoader()
        {
            if (!m_InitializationComplete)
            {
                Debug.LogWarning(
                    "Call to DeinitializeLoader without an initialized manager." +
                    "Please make sure wait for initialization to complete before calling this API.");
                return;
            }

            StopSubsystems();
            if (activeLoader != null)
            {
                activeLoader.Deinitialize();
                activeLoader = null;
            }

            m_InitializationComplete = false;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Attempts to append the given loader to the list of loaders at the given index.
        /// </summary>
        /// <param name="loader">
        /// The <see cref="XRLoader"/> to be added to this manager's instance of loaders.
        /// </param>
        /// <param name="index">
        /// The index at which the given <see cref="XRLoader"/> should be added. If you set a negative or otherwise
        /// invalid index, the loader will be appended to the end of the list.
        /// </param>
        /// <returns>
        /// <c>true</c> if the loader is not a duplicate and was added to the list successfully, <c>false</c>
        /// otherwise.
        /// </returns>
        /// <remarks>
        /// This method behaves differently in the Editor and during runtime/Play mode. While your app runs in the Editor and not in
        /// Play mode, attempting to add an <see cref="XRLoader"/> will always succeed and register that loader's type
        /// internally. Attempting to add a loader during runtime/Play mode will trigger a check to see whether a loader of
        /// that type was registered. If the check is successful, the loader is added. If not, the loader is not added and the method
        /// returns <c>false</c>.
        /// </remarks>
        public bool TryAddLoader(XRLoader loader, int index = -1)
        {
            if (loader == null || !CheckLoaderRegistration(loader))
            {
                return(false);
            }

#if UNITY_EDITOR
            m_RegisteredLoaders.Add(loader);
#endif

            if (index < 0 || index >= currentLoaders.Count)
            {
                currentLoaders.Add(loader);
            }
            else
            {
                currentLoaders.Insert(index, loader);
            }

            return(true);
        }