示例#1
0
    //Game First Scene Loaded
    IEnumerator FirstLoadedScene(WhichMode sceneToLoad)
    {
        //Unload All other Scenes than Menu
        if (SceneManager.GetActiveScene().name != "Scene Testing")
        {
            for (int i = 0; i < SceneManager.sceneCount; i++)
            {
                if (SceneManager.GetSceneAt(i).name != "Scene Testing" && SceneManager.GetSceneAt(i).name != "Menu" && !GlobalVariables.Instance.environementScenes.Contains(SceneManager.GetSceneAt(i).name))
                {
                    yield return(SceneManager.UnloadSceneAsync(SceneManager.GetSceneAt(i).name));
                }
            }
        }

        for (int i = 0; i < SceneManager.sceneCountInBuildSettings; i++)
        {
            if (SceneManager.GetSceneByBuildIndex(i).isLoaded&& SceneManager.GetSceneByBuildIndex(i).name != "Scene Testing" && SceneManager.GetSceneByBuildIndex(i).name != "Menu")
            {
                yield return(SceneManager.UnloadSceneAsync(SceneManager.GetSceneByBuildIndex(i).name));
            }
        }

        //Unload Scene if already loaded
        if (SceneManager.GetSceneByName(sceneToLoad.ToString()).isLoaded)
        {
            yield return(SceneManager.UnloadSceneAsync(sceneToLoad.ToString()));
        }


        if (SceneManager.GetActiveScene().name != "Scene Testing")
        {
            yield return(SceneManager.LoadSceneAsync(sceneToLoad.ToString(), LoadSceneMode.Additive));

            LevelWasLoaded(sceneToLoad, GameStateEnum.Menu);
        }
        else
        {
            //Scene Testing
            if (SceneManager.sceneCount > 1)
            {
                yield return(new WaitUntil(() => SceneManager.GetSceneAt(1).isLoaded));

                LevelWasLoaded((WhichMode)Enum.Parse(typeof(WhichMode), SceneManager.GetSceneAt(1).name), GameStateEnum.Playing);
            }
            else
            {
                yield return(SceneManager.LoadSceneAsync(sceneToLoad.ToString(), LoadSceneMode.Additive));

                LevelWasLoaded(sceneToLoad, GameStateEnum.Playing);
            }
        }
    }
示例#2
0
    //Menu Load Scene to choose mode
    IEnumerator LoadScene(WhichMode sceneToLoad, GameStateEnum gameState = GameStateEnum.Menu, bool resetStats = true)
    {
        if (SceneManager.GetSceneByName(GlobalVariables.Instance.CurrentModeLoaded.ToString()).isLoaded)
        {
            yield return(SceneManager.UnloadSceneAsync(GlobalVariables.Instance.CurrentModeLoaded.ToString()));
        }

        DestroyParticules();

        yield return(SceneManager.LoadSceneAsync(sceneToLoad.ToString(), LoadSceneMode.Additive));

        LevelWasLoaded(sceneToLoad, gameState);

        if (resetStats)
        {
            StatsManager.Instance.ResetStats();
        }
    }