Exemplo n.º 1
0
        IEnumerator SeamlessSceneDaemon(float waitTime)
        {
            while (true)
            {
                yield return(new WaitForSeconds(waitTime));

                string[] sceneNames = new string[seamleassScenes.Count];
                seamleassScenes.Keys.CopyTo(sceneNames, 0);
                foreach (string sceneName in sceneNames)
                {
                    SceneState sceneState = seamleassScenes[sceneName];
                    bool       loaded     = SceneManager.GetSceneByName(sceneName).isLoaded;

                    if (sceneState.Equals(SceneState.TO_LOAD) && !loaded)
                    {
                        seamleassScenes[sceneName] = SceneState.LOADING;
                        yield return(SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive));
                    }
                    else if (sceneState.Equals(SceneState.TO_UNLOAD) && loaded)
                    {
                        seamleassScenes[sceneName] = SceneState.UNLOADING;
                        yield return(SceneManager.UnloadSceneAsync(sceneName));
                    }
                    else if (sceneState.Equals(SceneState.LOADING) && loaded)
                    {
                        seamleassScenes[sceneName] = SceneState.LOADED;
                    }
                    else if ((sceneState.Equals(SceneState.UNLOADING) || sceneState.Equals(SceneState.TO_UNLOAD)) && !loaded)
                    {
                        seamleassScenes.Remove(sceneName);
                    }
                }
            }
        }