63 lines
1.1 KiB
C#
63 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class ScreenTransitionManager : MonoBehaviour
|
|
{
|
|
|
|
public FadeScreen fadeScreen;
|
|
|
|
|
|
public void GoToScene(int sceneIndex)
|
|
{
|
|
StartCoroutine(GoToSceneRoutine(sceneIndex));
|
|
|
|
}
|
|
|
|
|
|
IEnumerator GoToSceneRoutine(int sceneIndex)
|
|
{
|
|
|
|
fadeScreen.FadeOut();
|
|
yield return new WaitForSeconds(fadeScreen.fadeDuration);
|
|
|
|
// Launch the new scene
|
|
SceneManager.LoadScene(sceneIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void GoToSceneAsync(int sceneIndex)
|
|
{
|
|
StartCoroutine(GoToSceneAsyncRoutine(sceneIndex));
|
|
|
|
}
|
|
|
|
|
|
IEnumerator GoToSceneAsyncRoutine(int sceneIndex)
|
|
{
|
|
|
|
fadeScreen.FadeOut();
|
|
|
|
// Launch the new scene
|
|
AsyncOperation operation = SceneManager.LoadSceneAsync(sceneIndex);
|
|
operation.allowSceneActivation = false;
|
|
|
|
float timer = 0;
|
|
while(timer >= fadeScreen.fadeDuration && !operation.isDone)
|
|
{
|
|
timer += Time.deltaTime;
|
|
yield return null;
|
|
|
|
}
|
|
|
|
operation.allowSceneActivation = true;
|
|
|
|
}
|
|
|
|
|
|
}
|