Example #1
0
    /// <summary>
    /// Method call to wrap up any last steps of the scene loading process. The last of which is self-destructing.
    /// </summary>
    void finishLoading()
    {
        //GameObject[] gos = loadingScene.GetRootGameObjects();

        GameObject loadingScreenGameObj = GameObject.FindGameObjectWithTag("loadingScreen");

        if (loadingScreenGameObj != null)
        {
            Animator anim = loadingScreenGameObj.GetComponent <Animator>();
            anim.Play("unloadingScreen", -1);
            Object.Destroy(anim.gameObject, 2f);
        }
        Object.Destroy(this.gameObject);
        levelState = LevelLoadingProcess.Done;

        if (sceneLoadComplete != null)
        {
            sceneLoadComplete();
        }
    }
Example #2
0
    /// <summary>
    /// Iterate through the scene loading process, as defined by the LevelLoadingProgress enum, and complete upon reaching its end. This method will trigger several events at perscribed points in the process.
    /// </summary>
    IEnumerator switchScene()
    {
        while (levelState != LevelLoadingProcess.Done)
        {
            levelState += 1;

            switch (levelState)
            {
            case LevelLoadingProcess.LoadingScreen:
                //			currentScene = SceneManager.GetActiveScene(); //this.gameObject.scene;
                setAsPermanent();
                SceneManager.LoadScene(LOADING_SCREEN_NAME, LoadSceneMode.Additive);
                break;

            case LevelLoadingProcess.SetActiveLoadingScreen:
                PlayerInput input = FindObjectOfType <PlayerInput>();
                if (input != null)
                {
                    input.gameObject.SetActive(false);
                }
                loadingScene = SceneManager.GetSceneByName(LOADING_SCREEN_NAME);
                if (loadingScene.name != null)
                {
                    SceneManager.SetActiveScene(loadingScene);
                }
                break;

            case LevelLoadingProcess.FadeMusic:
                if (fadeMusic != null)
                {
                    fadeMusic();
                }
                break;

            case LevelLoadingProcess.LoadNextScene:
                if (sceneLoadStart != null)
                {
                    sceneLoadStart();
                }
                targetContainer.loadScenes();
                if (sceneLoadEnd != null)
                {
                    sceneLoadEnd();
                }
                break;

            case LevelLoadingProcess.SetActiveNextScene:
                Scene activeScene = SceneManager.GetSceneByName(targetContainer.sceneNames[0]);
                if (activeScene.isLoaded == false)
                {
                    levelState -= 1;                             //pause the process until this scene is successfully loaded
                }
                else
                {
                    SceneManager.SetActiveScene(activeScene);
                }
                break;

            case LevelLoadingProcess.UnloadCurrentScene:
                if (targetContainer == currentSceneContainer)
                {
                    break;
                }
                if (currentSceneContainer != null)
                {
                    currentSceneContainer.unloadAll();
                }
                else
                {
                    foreach (Scene currentScene in currentScenes)
                    {
                        if (currentScene.isLoaded != false)
                        {
                            SceneManager.UnloadSceneAsync(currentScene);
                        }
                    }
                }
                turnOffMenuCam();
                break;

            case LevelLoadingProcess.LoadGui:
                if (sceneLoadGUI != null)
                {
                    sceneLoadGUI();
                }
                targetContainer.loadGUI();
                targetContainer.loadBackground();
                break;

            case LevelLoadingProcess.LoadSceneSettings:
                //GameManager gameManager = FindObjectOfType<GameManager>();
                //if (gameManager != null)
                //{
                //	if (targetContainer.stageSettings != null)
                //	{
                //		gameManager.stageSettings = targetContainer.stageSettings;
                //	}
                //	else
                //	{
                //		gameManager.revertToDefaultSettings();
                //	}
                //}
                break;

            case LevelLoadingProcess.LoadPlayerSaveData:
                if (sceneLoadPlayerSaveData != null)
                {
                    sceneLoadPlayerSaveData();
                }
                break;

            case LevelLoadingProcess.Done:
                if (targetContainer.guiIsActive == false)
                {
                    addEventSysIfNeeded();
                }
                finishLoading();
                break;

            default:
                break;
            }

            yield return(null);
        }
    }