シーン システムのコンテンツの読み込み — MRTK2

コンテンツの読み込み操作はすべて非同期であり、また、既定ではすべてのコンテンツ読み込みが付加的に行われます。 マネージャーや照明シーンが、コンテンツ読み込み操作の影響を受けることはありません。 読み込みの進行状況とシーンのアクティブ化の監視については、「コンテンツの読み込みを監視する」を参照してください。

コンテンツの読み込み

コンテンツのシーンを読み込むには、LoadContent メソッドを使用します。

IMixedRealitySceneSystem sceneSystem = MixedRealityToolkit.Instance.GetService<IMixedRealitySceneSystem>();

// Additively load a single content scene
await sceneSystem.LoadContent("MyContentScene");

// Additively load a set of content scenes
await sceneSystem.LoadContent(new string[] { "MyContentScene1", "MyContentScene2", "MyContentScene3" });

単一シーンの読み込み

単一シーン読み込みに相当する処理は、オプションの mode 引数を用いて実現できます。 LoadSceneMode.Single では、読み込み処理に進む前に、まず、読み込まれているコンテンツ シーンがすべてアンロードされます。

IMixedRealitySceneSystem sceneSystem = MixedRealityToolkit.Instance.GetService<IMixedRealitySceneSystem>();

// ContentScene1, ContentScene2 and ContentScene3 will be loaded additively
await sceneSystem.LoadContent("ContentScene1");
await sceneSystem.LoadContent("ContentScene2");
await sceneSystem.LoadContent("ContentScene3");

// ContentScene1, ContentScene2 and ContentScene3 will be unloaded
// SingleContentScene will be loaded additively
await sceneSystem.LoadContent("SingleContentScene", LoadSceneMode.Single);

次のシーンと前のシーンの読み込み

コンテンツは、ビルド インデックスの順に 1 つずつ読み込むことができます。 一連のデモンストレーション シーンを 1 つずつユーザーに紹介するショーケース アプリケーションで有効活用できます。

プレーヤー設定のビルドの現在のシーン

前後のコンテンツの読み込みでは、前のコンテンツを確実にアンロードするために、LoadSceneMode.Single が既定で使用されることに注意してください。

IMixedRealitySceneSystem sceneSystem = MixedRealityToolkit.Instance.GetService<IMixedRealitySceneSystem>();

if (nextSceneRequested && sceneSystem.NextContentExists)
{
    await sceneSystem.LoadNextContent();
}

if (prevSceneRequested && sceneSystem.PrevContentExists)
{
    await sceneSystem.LoadPrevContent();
}

PrevContentExists は、ビルド インデックスが、現在読み込まれている最小のインデックスよりも小さいコンテンツ シーンが少なくとも 1 つ存在する場合に true を返します。 NextContentExists は、ビルド インデックスが、現在読み込まれている最大のインデックスよりも大きいコンテンツ シーンが少なくとも 1 つ存在する場合に true を返します。

wrap 引数が true の場合、コンテンツは、先頭または最後のビルド インデックスにループ バックします。 したがって、前後のコンテンツの存在をチェックする必要はありません。

IMixedRealitySceneSystem sceneSystem = MixedRealityToolkit.Instance.GetService<IMixedRealitySceneSystem>();

if (nextSceneRequested)
{
    await sceneSystem.LoadNextContent(true);
}

if (prevSceneRequested)
{
    await sceneSystem.LoadPrevContent(true);
}

タグによる読み込み

タグによるコンテンツ シーンの読み込み

コンテンツ シーンを複数まとめて読み込んだ方が望ましい場合もあります。 たとえば、体験ステージは、複数のシーンで構成されている場合があり、正しく機能するためには、すべてのシーンが同時に読み込まれなければなりません。 シーンにタグを付けたうえで、そのタグを使用して読み込んだりアンロードしたりすれば簡単です。

IMixedRealitySceneSystem sceneSystem = MixedRealityToolkit.Instance.GetService<IMixedRealitySceneSystem>();

await LoadContentByTag("Stage1");

// Wait until stage 1 is complete

await UnloadContentByTag("Stage1");
await LoadContentByTag("Stage2);

また、体験版に組み込む要素をアーティストが選別する場合にも、タグによる読み込みを使用すれば、スクリプトに変更を加える必要がありません。 たとえば、以下の 2 セットのタグでこのスクリプトを実行した場合、それぞれ異なる結果が得られます。

IMixedRealitySceneSystem sceneSystem = MixedRealityToolkit.Instance.GetService<IMixedRealitySceneSystem>();

await LoadContentByTag("Terrain");
await LoadContentByTag("Structures");
await LoadContentByTag("Vegetation");

テスト コンテンツ

シーン名 シーン タグ スクリプトによる読み込み
DebugTerrainPhysics Terrain
StructureTesting 構造
VegetationTools Vegetation
Mountain Terrain
Cabin 構造
ツリー Vegetation

最終コンテンツ

シーン名 シーン タグ スクリプトによる読み込み
DebugTerrainPhysics DoNotInclude
StructureTesting DoNotInclude
VegetationTools DoNotInclude
Mountain Terrain
Cabin 構造
ツリー Vegetation

エディターの動作

これらの操作はいずれも、エディターやプレイ モードから、シーン システムのサービス インスペクターを使用して実行できます。編集モードでは、シーンの読み込みが瞬時に行われるのに対し、プレイ モードでは、読み込みの進行状況を観察したり、ライセンス認証トークンを使用したりすることができます。

コンテンツの読み込みが強調表示されたインスペクターのシーン システム