浏览代码

Added check to avoid loading scene multiple times

/main
Unknown 4 年前
当前提交
23f0a3bf
共有 1 个文件被更改,包括 26 次插入5 次删除
  1. 31
      UOP1_Project/Assets/Scripts/Scriptable Objects/SceneManagement/ScenesData.cs

31
UOP1_Project/Assets/Scripts/Scriptable Objects/SceneManagement/ScenesData.cs


{
for (int i = 0; i < scenesToLoadNames.Count; ++i)
{
//Add the scene to the list of scenes to load asynchronously in the background
scenesToLoad.Add(SceneManager.LoadSceneAsync(scenesToLoadNames[i], LoadSceneMode.Additive));
//Remove scene from list of scenes to load
scenesToLoadNames.Remove(scenesToUnLoadNames[i]);
if (!CheckLoadState(scenesToLoadNames[i]))
{
//Add the scene to the list of scenes to load asynchronously in the background
scenesToLoad.Add(SceneManager.LoadSceneAsync(scenesToLoadNames[i], LoadSceneMode.Additive));
//Remove scene from list of scenes to load
//scenesToUnLoadNames.Add(scenesToLoadNames[i]);
scenesToLoadNames.Remove(scenesToLoadNames[i]);
}
for (int i = 0; i < scenesToLoad.Count; ++i)
for (int i = 0; i < scenesToUnLoadNames.Count; ++i)
{
//Add the scene to the list of scenes to unload asynchronously in the background
SceneManager.UnloadSceneAsync(scenesToUnLoadNames[i]);

}
public bool CheckLoadState(String sceneName)
{
if (SceneManager.sceneCount > 0)
{
for (int i = 0; i < SceneManager.sceneCount; ++i)
{
Scene scene = SceneManager.GetSceneAt(i);
if (scene.name == sceneName)
{
return true;
}
}
}
return false;
}
//Start next level

正在加载...
取消
保存