Exemplo n.º 1
0
    /// <summary>
    /// Load async
    /// </summary>
    /// <returns></returns>
    IEnumerator LoadAsynchronously()
    {
        AsyncOperation loadingOperation = SceneManager.LoadSceneAsync(sceneIndex);

        loadingScreen.SetActive(true);

        while (!loadingOperation.isDone)
        {
            float loadingProgress = Mathf.Clamp01(loadingOperation.progress / .9f);
            sliderLevelLoader.value = loadingProgress;
            yield return(null); //Waiting a frame before continuing after the previous line
        }

        if (loadingOperation.isDone)
        {
            loadingScreen.SetActive(false);
            duringGameUI.SetActive(true);

            if (SceneManager.GetActiveScene().buildIndex != 0)
            {
                if (SceneManager.GetActiveScene().buildIndex != 2)
                {
                    FindObjectOfType <UpgradesAndGameplayController>().SetGameplayValuesByUpgradeIndex();
                    MainMenuHandler.levelLoaded.Value = true;

                    if (PlayerPrefs.HasKey(PlayerPrefsStrings.dontDisplayAgainTutorial))
                    {
                        //If value is one, don't display was checked by the user
                        if (PlayerPrefs.GetInt(PlayerPrefsStrings.dontDisplayAgainTutorial) == 1)
                        {
                            // do nothing
                        }
                        else
                        {
                            TutorialController.ActivateTutorialObjects();
                        }
                    }
                    else
                    {
                        PlayerPrefs.SetInt(PlayerPrefsStrings.dontDisplayAgainTutorial, 0);
                        TutorialController.ActivateTutorialObjects();
                    }


                    GameOverScreenController.gameOver.Value = false;
                    FindObjectOfType <UpgradesAndGameplayController>().SetGameplayValuesByUpgradeIndex();
                    FindObjectOfType <RelicUsageController>().SetAlphaToMax();
                }
            }
            else
            {
                MainMenuHandler.levelLoaded.Value = false;
                duringGameUI.SetActive(false);
                GameObject.FindGameObjectWithTag("audioManager").GetComponent <AudioManager>().PlaySound("menuTheme");
            }
        }
    }