Switching Scenes
To switch scenes, you unload the loaded scene context and then load a new scene. Scenes loaded as child contexts can be unloaded all at once by calling SceneContextLoader.UnloadAllScenesAsync()
.
await sceneContextLoader.UnloadAllAsync();
await sceneContextLoader.LoadAsync(nextScene, active: true);
To unload a specific scene, keep the return value of LoadAsync()
and call UnloadAsync()
at the necessary timing.
var sceneContext = await sceneContextLoader.LoadAsync(firstScene, active: true);
...
await sceneContextLoader.UnloadAsync(sceneContext);
await sceneContextLoader.LoadAsync(nextScene, active: true);
Closing Your Own Scene Context Space and Opening Another Scene Context
To close the scene context you belong to, go through IContext.OwnerSceneContextLoader
.
[SerializeField] public SceneAssetReference nextSceneAssetReference;
public IContext Context { get; set; }
[Inject]
void Constrruct(IContext context)
{
Context = context;
}
public void LoadNextScene()
{
await Context.OwnerSceneContextLoader.UnloadAllScenesAsync();
await Context.OwnerSceneContextLoader.LoadAsync(nextSceneAssetReference, active: true);
}
Last modified: 27 December 2024