Updated Scene Loader to use Unitask and wait for unload to finish before loading new scene
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using Cysharp.Threading.Tasks;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -45,4 +46,26 @@ public class SceneLoader : MonoBehaviour
|
|||||||
{
|
{
|
||||||
SceneManager.LoadScene("CurrentResults", LoadSceneMode.Additive);
|
SceneManager.LoadScene("CurrentResults", LoadSceneMode.Additive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void NewRoom()
|
||||||
|
{
|
||||||
|
LoadNewRoom();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async UniTaskVoid LoadNewRoom()
|
||||||
|
{
|
||||||
|
int sceneCount = SceneManager.sceneCount;
|
||||||
|
|
||||||
|
for (int i = 0; i < sceneCount; i++)
|
||||||
|
{
|
||||||
|
Scene myScene = SceneManager.GetSceneAt(i);
|
||||||
|
if (myScene.isLoaded && myScene != SceneManager.GetSceneByBuildIndex(baseSceneIndex))
|
||||||
|
{
|
||||||
|
currentScene = myScene.buildIndex;
|
||||||
|
await SceneManager.UnloadSceneAsync(myScene);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await SceneManager.LoadSceneAsync(currentScene + 1, LoadSceneMode.Additive);
|
||||||
|
Debug.Log("Loaded Room " + currentScene + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user