public IEnumerator LoadNextScene()
{
// load next scene
SceneManager.LoadScene(nextScene.ToString(), LoadSceneMode.Additive);
// wait one frame for scene to load
yield return null;
// set the active scene as soon as it's ready
var scene = SceneManager.GetSceneByName(nextScene.ToString());
SceneManager.SetActiveScene(scene);
// move existing draw calls to new active scene
foreach(var dc in UIDrawCall.activeList)
{
SceneManager.MoveGameObjectToScene(dc.gameObject, scene);
}
foreach (var dc in UIDrawCall.inactiveList)
{
SceneManager.MoveGameObjectToScene(dc.gameObject, scene);
}
// unload previous scene
SceneManager.UnloadScene(previousScene.ToString());
}