protected IEnumerator loadNextScene()
{
// let the listener know the screen is obscured if we have one
if( onScreenObscured != null )
onScreenObscured();
// if we arent loading a new scene we just set the flag as if we did so that 2 phase transitions complete
if( !_loadsNewScene )
{
_isNewSceneLoaded = true;
yield break;
}
if( loadSceneOnBackgroundThread )
{
// load the Scene on a background thread
var syncContext = SynchronizationContext.Current;
Task.Run( () =>
{
var scene = sceneLoadAction();
// get back to the main thread before setting the new Scene active
syncContext.Post( d =>
{
Core.scene = scene;
_isNewSceneLoaded = true;
}, null );
} );
}
else
{
Core.scene = sceneLoadAction();
_isNewSceneLoaded = true;
}
// wait for the scene to load if it was loaded on a background thread
while( !_isNewSceneLoaded )
yield return null;
}