86 lines
2.0 KiB
C#
86 lines
2.0 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
namespace Scampz.GameJam
|
|
{
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
public static GameManager Instance;
|
|
|
|
void Awake()
|
|
{
|
|
if (Instance == null)
|
|
{
|
|
Instance = this;
|
|
}
|
|
}
|
|
|
|
public void LoadScene(int levelIndex, LoadSceneMode loadSceneMode)
|
|
{
|
|
StartCoroutine(LoadSceneAsync(levelIndex, loadSceneMode));
|
|
}
|
|
|
|
public void UnloadScene(int levelIndex)
|
|
{
|
|
StartCoroutine(UnloadSceneAsync(levelIndex));
|
|
}
|
|
|
|
public void LoadScene(string sceneName, LoadSceneMode loadSceneMode)
|
|
{
|
|
StartCoroutine(LoadSceneAsync(sceneName, loadSceneMode));
|
|
}
|
|
|
|
public void UnloadScene(string sceneName)
|
|
{
|
|
StartCoroutine(UnloadSceneAsync(sceneName));
|
|
}
|
|
|
|
IEnumerator LoadSceneAsync(int levelIndex, LoadSceneMode loadSceneMode)
|
|
{
|
|
yield return null;
|
|
|
|
var loadSceneOperation = SceneManager.LoadSceneAsync(levelIndex, loadSceneMode);
|
|
loadSceneOperation.allowSceneActivation = false;
|
|
while (!loadSceneOperation.isDone)
|
|
{
|
|
if (loadSceneOperation.progress >= 0.9f)
|
|
break;
|
|
}
|
|
|
|
loadSceneOperation.allowSceneActivation = true;
|
|
yield return loadSceneOperation;
|
|
}
|
|
|
|
private IEnumerator UnloadSceneAsync(int levelIndex)
|
|
{
|
|
yield return null;
|
|
|
|
SceneManager.UnloadSceneAsync(levelIndex);
|
|
}
|
|
|
|
private IEnumerator LoadSceneAsync(string sceneName, LoadSceneMode loadSceneMode)
|
|
{
|
|
yield return null;
|
|
var loadSceneOperation = SceneManager.LoadSceneAsync(sceneName, loadSceneMode);
|
|
loadSceneOperation.allowSceneActivation = false;
|
|
while (!loadSceneOperation.isDone)
|
|
{
|
|
if (loadSceneOperation.progress >= 0.9f)
|
|
break;
|
|
}
|
|
|
|
loadSceneOperation.allowSceneActivation = true;
|
|
yield return loadSceneOperation;
|
|
}
|
|
|
|
private IEnumerator UnloadSceneAsync(string sceneName)
|
|
{
|
|
yield return null;
|
|
|
|
SceneManager.UnloadSceneAsync(sceneName);
|
|
}
|
|
|
|
}
|
|
}
|