Exemplo n.º 1
0
    //*************************//
    //    Private Functions    //
    //*************************//

    private IEnumerator TransitionCoroutine(string _sceneName, GameObject _player, SpawnPointData _spawnPoint = null, Action _callback = null)
    {
        m_transitioning = true;
        float halfTransitionTime = m_transitionTime / 2f;

        if (_player.activeInHierarchy)
        {
            _player.GetComponent <PlayerMovement>().DisableUserInput(true);
        }

        m_fader.FadeIn(halfTransitionTime);
        yield return(new WaitForSeconds(halfTransitionTime));

        List <Scene> loadedScenes = new List <Scene>();

        for (int i = 0; i < SceneManager.sceneCount; i++)
        {
            loadedScenes.Add(SceneManager.GetSceneAt(i));
        }

        foreach (Scene scene in loadedScenes)
        {
            AsyncOperation unloadSceneAsync = null;
            if (scene.buildIndex != 0 && scene.isLoaded)
            {
                unloadSceneAsync = SceneManager.UnloadSceneAsync(scene);
                while (unloadSceneAsync != null && !unloadSceneAsync.isDone)
                {
                    yield return(null);
                }
            }
        }

        _player.SetActive(false);

        AsyncOperation loadSceneAsync = null;

        if (!SceneManager.GetSceneByName(_sceneName).isLoaded)
        {
            loadSceneAsync = SceneManager.LoadSceneAsync(_sceneName, LoadSceneMode.Additive);
            while (loadSceneAsync != null && !loadSceneAsync.isDone)
            {
                Debug.LogFormat("{0}: Loading scene: {1}%", name, loadSceneAsync.progress * 100f);
                yield return(null);
            }
        }

        Scene toScene = SceneManager.GetSceneByName(_sceneName);

        SceneManager.SetActiveScene(toScene);

        if (_spawnPoint != null)
        {
            AreaController controller = FindObjectOfType <AreaController>();
            controller.InitializeArea(_player, _spawnPoint);

            _player.SetActive(true);
            _player.GetComponent <PlayerMovement>().DisableUserInput(false);
        }

        m_fader.FadeOut(halfTransitionTime);
        m_transitioning = false;

        SceneManager.SetActiveScene(SceneManager.GetSceneByBuildIndex(0));

        _callback?.Invoke();
        onAreaLoaded?.Invoke();
    }
Exemplo n.º 2
0
    private void Start()
    {
        AreaController controller = FindObjectOfType <AreaController>();

        controller.InitializeArea(player, controller.area.spawnPoints[0]);
    }