private IEnumerator loadSceneAsync(string name, BaseSceneFader fader) { var loadOp = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(name); loadOp.allowSceneActivation = false; float passedTime = 0; //A progress of 0.9 indicates that the scene data is loaded into memory and ready to be switched to. while (loadOp.progress < 0.9f || passedTime < FadeTime) { yield return(null); passedTime += Time.unscaledDeltaTime; fader.SetFadeAlpha(Mathf.Clamp(passedTime / FadeTime, 0, 1)); fader.SetProgress(Mathf.Clamp(loadOp.progress / 0.9f, 0, 1)); } loadOp.allowSceneActivation = true; yield return(new WaitUntil(() => loadOp.isDone)); passedTime = 0; //A progress of 0.9 indicates that the scene data is loaded into memory and ready to be switched to. while (passedTime < FadeTime) { yield return(null); passedTime += Time.unscaledDeltaTime; fader.SetFadeAlpha(Mathf.Clamp(1 - passedTime / FadeTime, 0, 1)); } Destroy(fader.gameObject); }
public void LoadScene(string name, out Coroutine coroutine) { BaseSceneFader fader = Instantiate(FaderPrefab); fader.Init(FadeColor, TransitionBackground, ShowProgressBar); DontDestroyOnLoad(fader.gameObject); coroutine = fader.StartCoroutine(loadSceneAsync(name, fader)); }
public void LoadScene(int id, out Coroutine coroutine) { BaseSceneFader fader = Instantiate(FaderPrefab); fader.Init(FadeColor, TransitionBackground, ShowProgressBar); DontDestroyOnLoad(fader.gameObject); coroutine = fader.StartCoroutine(loadSceneAsync(UnityEngine.SceneManagement.SceneManager.GetSceneByBuildIndex(id).name, fader)); }