protected IEnumerator UnloadSceneAsync(IScene sceneRoot)
        {
            var sceneLoader = SceneLoaders.FirstOrDefault(loader => loader.SceneType == sceneRoot.GetType()) ??
                              _defaultSceneLoader;

            Action <float, string> updateDelegate = (v, m) =>
            {
                this.Publish(new SceneLoaderEvent()
                {
                    State           = SceneState.Unloading,
                    Progress        = v,
                    ProgressMessage = m
                });
            };

            yield return(StartCoroutine(sceneLoader.Unload(sceneRoot, updateDelegate)));

            LoadedScenes.Remove(sceneRoot);
            this.Publish(new SceneLoaderEvent()
            {
                State = SceneState.Unloaded, SceneRoot = sceneRoot
            });

            AsyncOperation unloadSceneAsync = SceneManager.UnloadSceneAsync(((MonoBehaviour)sceneRoot).gameObject.scene);

            while (!unloadSceneAsync.isDone)
            {
                yield return(null);
            }

            this.Publish(new SceneLoaderEvent()
            {
                State = SceneState.Destructed, SceneRoot = sceneRoot
            });
        }
        protected IEnumerator UnloadSceneAsync(IScene sceneRoot)
        {
            var sceneLoader = SceneLoaders.FirstOrDefault(loader => loader.SceneType == sceneRoot.GetType()) ??
                              _defaultSceneLoader;

            Action <float, string> updateDelegate = (v, m) => {
                this.Publish(new SceneLoaderEvent()
                {
                    State           = SceneState.Unloading,
                    Progress        = v,
                    ProgressMessage = m
                });
            };

            yield return(StartCoroutine(sceneLoader.Unload(sceneRoot, updateDelegate)));

            this.Publish(new SceneLoaderEvent()
            {
                State = SceneState.Unloaded, SceneRoot = sceneRoot
            });

            LoadedScenes.Remove(sceneRoot);
            Destroy((sceneRoot as MonoBehaviour).gameObject);
            UnityEngine.SceneManagement.SceneManager.UnloadScene(sceneRoot.Name);

            this.Publish(new SceneLoaderEvent()
            {
                State = SceneState.Destructed, SceneRoot = sceneRoot
            });
        }
Example #3
0
 /// <summary>
 /// Disposes of a Scene.
 /// </summary>
 /// <param name="name"></param>
 public void DisposeScene(string name)
 {
     if (CurrentScene == LoadedScenes[name])
     {
         CurrentScene = null;
     }
     LoadedScenes[name].Dispose();
     LoadedScenes.Remove(name);
 }