/// <summary>
        /// Loads the reference as a scene.
        /// </summary>
        /// <returns>The operation handle for the scene load.</returns>
        public virtual AsyncOperationHandle <SceneInstance> LoadSceneAsync()
        {
            var result = Addressables.LoadSceneAsync(RuntimeKey);

            m_Operation = result;
            return(result);
        }
Exemple #2
0
        public static void LoadScene(string key, Action <Scene> onSucceeded, Action <string> onFailed = null,
                                     LoadSceneMode loadMode = LoadSceneMode.Single, bool activeOnLoad = true, int priority = 100)
        {
            if (!GuardKey(key, out key))
            {
                onFailed?.Invoke(key);
                return;
            }

            if (_scenes.ContainsKey(key))
            {
                onSucceeded?.Invoke(_scenes[key].Scene);
                return;
            }

            try
            {
                var operation = Addressables.LoadSceneAsync(key, loadMode, activeOnLoad, priority);
                operation.Completed += handle => OnLoadSceneCompleted(handle, key, onSucceeded, onFailed);
            }
            catch (Exception ex)
            {
                if (ExceptionHandle == ExceptionHandleType.Throw)
                {
                    throw ex;
                }

                if (ExceptionHandle == ExceptionHandleType.Log)
                {
                    Debug.LogException(ex);
                }
            }
        }
        /// <summary>
        /// Loads the reference as a scene.
        /// </summary>
        /// <param name="loadMode">Scene load mode.</param>
        /// <param name="activateOnLoad">If false, the scene will load but not activate (for background loading).  The SceneInstance returned has an Activate() method that can be called to do this at a later point.</param>
        /// <param name="priority">Async operation priority for scene loading.</param>
        /// <returns>The operation handle for the request.</returns>
        public virtual AsyncOperationHandle <SceneInstance> LoadSceneAsync(LoadSceneMode loadMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100)
        {
            var result = Addressables.LoadSceneAsync(RuntimeKey, loadMode, activateOnLoad, priority);

            m_Operation = result;
            return(result);
        }
Exemple #4
0
        /// <summary>
        /// Loads the reference as a scene.
        /// </summary>
        /// <param name="loadMode">Scene load mode.</param>
        /// <param name="activateOnLoad">If false, the scene will load but not activate (for background loading).  The SceneInstance returned has an Activate() method that can be called to do this at a later point.</param>
        /// <param name="priority">Async operation priority for scene loading.</param>
        /// <returns>The operation handle for the request if there is not a valid cached operation, otherwise return default operation</returns>
        public virtual AsyncOperationHandle <SceneInstance> LoadSceneAsync(LoadSceneMode loadMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100)
        {
            AsyncOperationHandle <SceneInstance> result = default(AsyncOperationHandle <SceneInstance>);

            if (m_Operation.IsValid())
            {
                Debug.LogError("Attempting to load AssetReference Scene that has already been loaded. Handle is exposed through getter OperationHandle");
            }
            else
            {
                result      = Addressables.LoadSceneAsync(RuntimeKey, loadMode, activateOnLoad, priority);
                m_Operation = result;
            }
            return(result);
        }
        public static void LoadScene(string key, LoadSceneMode loadMode, bool activeOnLoad = true, int priority = 100)
        {
            if (!GuardKey(key, out key))
            {
                return;
            }

            if (_scenes.ContainsKey(key))
            {
                return;
            }

            var operation = Addressables.LoadSceneAsync(key, loadMode, activeOnLoad, priority);

            operation.Completed += handle => OnLoadSceneCompleted(handle, key);
        }
        public static void LoadScene(string key, Action <Scene> onSucceeded, Action <string> onFailed = null,
                                     LoadSceneMode loadMode = LoadSceneMode.Single, bool activeOnLoad = true, int priority = 100)
        {
            if (!GuardKey(key, out key))
            {
                onFailed?.Invoke(key);
                return;
            }

            if (_scenes.ContainsKey(key))
            {
                onSucceeded?.Invoke(_scenes[key].Scene);
                return;
            }

            var operation = Addressables.LoadSceneAsync(key, loadMode, activeOnLoad, priority);

            operation.Completed += handle => OnLoadSceneCompleted(handle, key, onSucceeded, onFailed);
        }
        public static IEnumerator LoadSceneCoroutine(string key, LoadSceneMode loadMode = LoadSceneMode.Single, bool activeOnLoad = true, int priority = 100, Action <Scene> onSucceeded = null, Action <string> onFailed = null)
        {
            if (!GuardKey(key, out key))
            {
                onFailed?.Invoke(key);
            }
            else
            {
                if (_scenes.ContainsKey(key))
                {
                    onSucceeded?.Invoke(_scenes[key].Scene);
                }
                else
                {
                    var operation = Addressables.LoadSceneAsync(key, loadMode, activeOnLoad, priority);
                    yield return(operation);

                    OnLoadSceneCompleted(operation, key, onSucceeded, onFailed);
                }
            }
        }
        public static void LoadScene(string key, LoadSceneMode loadMode, bool activeOnLoad = true, int priority = 100)
        {
            if (!GuardKey(key, out key))
            {
                if (ExceptionHandle == ExceptionHandleType.Throw)
                {
                    throw new InvalidKeyException(key);
                }

                if (ExceptionHandle == ExceptionHandleType.Log)
                {
                    Debug.LogException(new InvalidKeyException(key));
                }

                return;
            }

            if (_scenes.ContainsKey(key))
            {
                return;
            }

            try
            {
                var operation = Addressables.LoadSceneAsync(key, loadMode, activeOnLoad, priority);
                operation.Completed += handle => OnLoadSceneCompleted(handle, key);
            }
            catch (Exception ex)
            {
                if (ExceptionHandle == ExceptionHandleType.Throw)
                {
                    throw ex;
                }

                if (ExceptionHandle == ExceptionHandleType.Log)
                {
                    Debug.LogException(ex);
                }
            }
        }