Example #1
0
    IEnumerator Loading(int sceneIndex, LoadSceneMode sceneMode)
    {
        StartLoading();
        yield return(new WaitForSecondsRealtime(1f));

        onFadeOutDone?.Invoke();
        loading = SceneManager.LoadSceneAsync(sceneIndex, sceneMode);
        Debug.Log("Loading screen:" + sceneIndex + " Mode:" + sceneMode);
        while (loading.progress < 1)
        {
            SetLoadingProgress(loading.progress * actualLoadingEndsAt);
            yield return(null);
        }

        SetLoadingProgress(actualLoadingEndsAt);
        randomNumber = (int)(actualLoadingEndsAt * 100);

        float delay = delayAfterActualLoading / iterationsForLoadingSimulation;

        for (int i = 0; i < iterationsForLoadingSimulation; i++)
        {
            randomNumber = Random.Range(randomNumber, 100);
            SetLoadingProgress(randomNumber / 100f);
            yield return(new WaitForSecondsRealtime(delay));
        }
        SetLoadingProgress(1);
        isLoading = false;
        if (loadingAnimator != null)
        {
            loadingAnimator.SetTrigger(fadeOutHash);
        }
    }
    IEnumerator FadeOut()
    {
        OnFadeOutStart?.Invoke(eventData);
        image.enabled = true;
        image.color   = Color.black;
        timer         = time;
        float process;

        while (timer >= 0)
        {
            timer      -= Time.deltaTime;
            process     = timer / time;
            image.color = new Color(0, 0, 0, process);
            yield return(0);
        }
        image.enabled = false;
        timer         = -0f;
        OnFadeOutDone?.Invoke(eventData);
    }