Updated Scene Loader to use Unitask and wait for unload to finish before loading new scene

This commit is contained in:
Thorbjoern
2025-06-27 10:48:27 +02:00
parent c9fb8b2d3b
commit c559c416fe
+23
View File
@@ -1,3 +1,4 @@
using Cysharp.Threading.Tasks;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@@ -45,4 +46,26 @@ public class SceneLoader : MonoBehaviour
{
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);
}
}