76 lines
1.8 KiB
C#
76 lines
1.8 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
namespace Scampz.GameJam
|
|
{
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
public Animator animator;
|
|
|
|
private static GameManager _instance;
|
|
|
|
public static GameManager Instance
|
|
{
|
|
get
|
|
{
|
|
if (!_instance)
|
|
{
|
|
_instance = new GameObject().AddComponent<GameManager>();
|
|
_instance.name = _instance.GetType().ToString();
|
|
DontDestroyOnLoad(_instance.gameObject);
|
|
}
|
|
|
|
return _instance;
|
|
}
|
|
}
|
|
void OnEnable()
|
|
{
|
|
//SceneManager.sceneLoaded += OnSceneLoaded;
|
|
}
|
|
|
|
void OnDisable()
|
|
{
|
|
//SceneManager.sceneLoaded -= OnSceneLoaded;
|
|
}
|
|
|
|
public void LoadScene(string sceneName, LoadSceneMode loadSceneMode)
|
|
{
|
|
StartCoroutine(LoadSceneAsync(sceneName, loadSceneMode));
|
|
}
|
|
|
|
public void UnloadScene(string sceneName)
|
|
{
|
|
StartCoroutine(UnloadSceneAsync(sceneName));
|
|
}
|
|
|
|
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;
|
|
if (SceneManager.GetSceneByName(sceneName).IsValid())
|
|
SceneManager.UnloadSceneAsync(sceneName);
|
|
}
|
|
|
|
private void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
|
|
{
|
|
//BGMManager.Instance.PlaySong();
|
|
}
|
|
}
|
|
}
|