シーンを切り替える
シーンを切り替えるには、ロードしたシーンコンテクストをアンロードしてから、新しいシーンをロードします。 子のコンテクストとしてロードしたシーンは SceneContextLoader.UnloadAllScenesAsync() を呼び出すことで、 すべてアンロードできます。
await sceneContextLoader.UnloadAllAsync();
await sceneContextLoader.LoadAsync(nextScene, active: true);
特定のシーンをアンロードするには、 LoadAsync() の戻り値を保持しておき、 必要なタイミングで UnloadAsync() を呼び出します。
var sceneContext = await sceneContextLoader.LoadAsync(firstScene, active: true);
...
await sceneContextLoader.UnloadAsync(sceneContext);
await sceneContextLoader.LoadAsync(nextScene, active: true);
自身のシーンコンテクスト空間を閉じて、別のシーンコンテクストを開く
自分自身の属するシーンコンテクストを閉じるには、 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: 26 July 2025