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
            });
        }
Пример #2
0
        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
            });
        }
Пример #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);
 }
Пример #4
0
        /// <summary>
        /// Loads a Scene from Scene Types. Use Set scene for already Loaded Scenes.
        /// </summary>
        public Scene LoadScene(string sceneTypeName, string newSceneName)
        {
            var a =
                (Scene)
                Activator.CreateInstance(SceneTypes[sceneTypeName], SpriteBatch, Graphics, GraphicsDevice, Window,
                                         Content, 1080, 720);

            LoadedScenes.Add(newSceneName, a);
            return(a);
        }
Пример #5
0
        public IEnumerator SetupScene(IScene sceneRoot)
        {
            this.Publish(new SceneLoaderEvent()
            {
                State     = SceneState.Instantiating,
                SceneRoot = sceneRoot
            });



            //If the scene was loaded via the api (it was queued having some name and settings)
            if (ScenesQueue.Count > 0)
            {
                var sceneQueueItem = ScenesQueue.Dequeue();
                sceneRoot.Name            = sceneQueueItem.Name;
                sceneRoot._SettingsObject = sceneQueueItem.Settings;
            }
            //Else, means scene was the start scene (loaded before kernel)
            else
            {
//				sceneRoot.Name = Application.loadedLevelName;
                sceneRoot.Name = UnityEngine.SceneManagement.SceneManager.GetSceneAt(UnityEngine.SceneManagement.SceneManager.sceneCount - 1).name;
            }


            this.Publish(new SceneLoaderEvent()
            {
                State     = SceneState.Instantiated,
                SceneRoot = sceneRoot
            });
            var sceneRootClosure = sceneRoot;
            Action <float, string> updateDelegate = (v, m) => {
                this.Publish(new SceneLoaderEvent()
                {
                    SceneRoot       = sceneRootClosure,
                    Name            = sceneRootClosure.Name,
                    State           = SceneState.Update,
                    Progress        = v,
                    ProgressMessage = m
                });
            };

            var sceneLoader = SceneLoaders.FirstOrDefault(loader => loader.SceneType == sceneRoot.GetType()) ??
                              _defaultSceneLoader;

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

            LoadedScenes.Add(sceneRoot);

            this.Publish(new SceneLoaderEvent()
            {
                State     = SceneState.Loaded,
                SceneRoot = sceneRoot
            });
        }
 public void LoadScene(string name, ISceneSettings settings, bool restrictToSingleScene)
 {
     if (restrictToSingleScene &&
         (LoadedScenes.Any(p => p.Name == name) || ScenesQueue.Any(p => p.Name == name) ||
          Application.loadedLevelName == name))
     {
         return;
     }
     this.QueueSceneLoad(name, settings);
     this.ExecuteLoad();
 }
Пример #7
0
        public void LoadScene(string name, ISceneSettings settings, bool restrictToSingleScene)
        {
            if (restrictToSingleScene &&
                (LoadedScenes.Any(p => p.Name == name) || ScenesQueue.Any(p => p.Name == name) ||
//                 Application.loadedLevelName == name)) return;
                 UnityEngine.SceneManagement.SceneManager.GetSceneAt(UnityEngine.SceneManagement.SceneManager.sceneCount - 1).name == name))
            {
                return;
            }
            this.QueueSceneLoad(name, settings);
            this.ExecuteLoad();
        }
Пример #8
0
        protected IEnumerator UnloadSceneAsync(string name)
        {
            var sceneRoot = LoadedScenes.FirstOrDefault(s => s.Name == name);

            if (sceneRoot != null)
            {
                yield return(StartCoroutine(this.UnloadSceneAsync(sceneRoot)));
            }
            else
            {
                yield break;
            }
        }
 public void QueueSceneLoadIfNotAlready(string sceneName, ISceneSettings settings)
 {
     if (LoadedScenes.Any(p => p.Name == sceneName) || ScenesQueue.Any(p => p.Name == sceneName) ||
         Application.loadedLevelName == sceneName)
     {
         return;
     }
     ScenesQueue.Enqueue(new SceneQueueItem()
     {
         Loader   = LoadSceneInternal(sceneName),
         Name     = sceneName,
         Settings = settings
     });
 }
Пример #10
0
        public void QueueSceneLoadIfNotAlready(string sceneName, ISceneSettings settings)
        {
            if (LoadedScenes.Any(p => p.Name == sceneName) || ScenesQueue.Any(p => p.Name == sceneName) ||
//			    Application.loadedLevelName == sceneName) {
                UnityEngine.SceneManagement.SceneManager.GetSceneAt(UnityEngine.SceneManagement.SceneManager.sceneCount - 1).name == sceneName)
            {
                return;
            }
            ScenesQueue.Enqueue(new SceneQueueItem()
            {
                Loader   = LoadSceneInternal(sceneName),
                Name     = sceneName,
                Settings = settings
            });
        }
 public void QueueScenesLoad(params SceneQueueItem[] items)
 {
     foreach (var item in items)
     {
         if (item.RestrictToSingleScene &&
             (LoadedScenes.Any(p => p.Name == name) || ScenesQueue.Any(p => p.Name == name) ||
              Application.loadedLevelName == name))
         {
             continue;
         }
         if (item.Loader == null)
         {
             item.Loader = LoadSceneInternal(item.Name);
         }
         ScenesQueue.Enqueue(item);
     }
 }
 public void Add(object objectToAdd)
 {
     if (objectToAdd is NodeNetwork)
     {
         LoadedNodeNetworks.Add(objectToAdd as NodeNetwork);
     }
     else if (objectToAdd is Scene)
     {
         LoadedScenes.Add(objectToAdd as Scene);
     }
     else if (objectToAdd is EmitterList)
     {
         LoadedEmitterLists.Add(objectToAdd as EmitterList);
     }
     else if (objectToAdd is ShapeCollection)
     {
         LoadedShapeCollections.Add(objectToAdd as ShapeCollection);
     }
 }
        private object LoadRfsAndAddToLists(ReferencedFileSave r, bool isBeingAccessed, IElement container)
        {
            string extension = FileManager.GetExtension(r.Name).ToLower();

            object runtimeObject = null;

            if (!r.LoadedOnlyWhenReferenced || isBeingAccessed)
            {
                switch (extension)
                {
                case "scnx":
                    runtimeObject = LoadScnx(r, container);
                    if ((!r.IsSharedStatic || container is ScreenSave) && runtimeObject != null)
                    {
                        LoadedScenes.Add(runtimeObject as Scene);
                    }
                    break;

                case "shcx":
                    runtimeObject = LoadShcx(r, container);
                    if ((!r.IsSharedStatic || container is ScreenSave) && runtimeObject != null)
                    {
                        LoadedShapeCollections.Add(runtimeObject as ShapeCollection);
                    }
                    break;

                case "nntx":
                    runtimeObject = LoadNntx(r, container);
                    if ((!r.IsSharedStatic || container is ScreenSave) && runtimeObject != null)
                    {
                        LoadedNodeNetworks.Add(runtimeObject as NodeNetwork);
                    }
                    break;

                case "emix":
                    runtimeObject = LoadEmix(r);
                    if ((!r.IsSharedStatic || container is ScreenSave) && runtimeObject != null)
                    {
                        LoadedEmitterLists.Add(runtimeObject as EmitterList);
                    }
                    break;

                case "achx":
                    runtimeObject = LoadAchx(r);
                    break;

                case "png":
                case "bmp":
                case "dds":
                case "tga":
                    runtimeObject = LoadTexture2D(r);
                    break;

                case "csv":
                    runtimeObject = LoadCsv(r);
                    break;

                case "fnt":
                    runtimeObject = LoadFnt(r);
                    break;

                case "splx":
                    runtimeObject = LoadSplx(r);
                    break;
                }
            }


            return(runtimeObject);
        }