Beispiel #1
0
    IEnumerator LoadSceneCoroutine(string sceneName, LoadSceneMode mode, ScreenTransitionType fadeIn, ScreenTransitionType fadeOut)
    {
        isTransitioning = true;
        switch (fadeIn)
        {
        case ScreenTransitionType.fade:
            yield return(StartCoroutine(FadeCoroutine(true)));

            break;
        }

        isWaitingOnLoad = true;

        SceneManager.LoadSceneAsync("LoadingScene");   // loads the loading scene

        while (isWaitingOnLoad)
        {
            yield return(null);
        }

        switch (fadeOut)
        {
        case ScreenTransitionType.fade:
            yield return(StartCoroutine(FadeCoroutine(false)));

            break;
        }
        float startTime = Time.time;

        isWaitingOnLoad = true;

        LoadingSceneManager loading = FindObjectOfType <LoadingSceneManager>();

        AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive); // Loads the current scene

        yield return(operation);

        float timeRemaining = timeLoadingMin - (Time.time - startTime);

        if (timeRemaining > 0)
        {
            yield return(new WaitForSeconds(timeRemaining));
        }

        if (loading != null)
        {
            loading.TrackProgress(operation);
        }
        else
        {
            Debug.LogError("No loading scene manager was found. Progress bar will not increase.");
        }

        switch (fadeIn)
        {
        case ScreenTransitionType.fade:
            yield return(StartCoroutine(FadeCoroutine(true)));

            break;
        }

        SceneManager.UnloadSceneAsync("LoadingScene");

        while (isWaitingOnLoad)
        {
            yield return(null);
        }

        switch (fadeOut)
        {
        case ScreenTransitionType.fade:
            yield return(StartCoroutine(FadeCoroutine(false)));

            break;
        }

        isTransitioning = false;
    }