ContentLoadInterface.LoadSceneAsync
Declaration
public static Unity.Loading.ContentSceneFile LoadSceneAsync(Unity.Content.ContentNamespace nameSpace, string filename, string sceneName, Unity.Loading.ContentSceneParameters sceneParams, NativeArray<ContentFile> dependencies, Unity.Jobs.JobHandle dependentFence);Параметры
| Параметр | Описание |
|---|---|
| зависимости | Список ContentFiles, на которые будет ссылаться загружаемый файл. Порядок должен соответствовать порядку, возвращённому процессом сборки. Значение ContentFile.GlobalTableDependency можно использовать, чтобы указать, что для разрешения ссылок следует применять PersistentManager. Это позволяет создавать ссылки на такие файлы, как "unity default resources". |
| nameSpace | ContentNamespace используется для фильтрации результатов. |
| имя файла | Путь к файлу на диске. |
| sceneName | Имя, которое будет применено к сцене. |
| sceneParams | Структура, которая собирает различные параметры в одном месте. |
| dependentFence | Загрузка не начнется до тех пор, пока это JobHandle не завершится. |
Возвращаемое значение
ContentSceneFile Обработка для доступа к результатам процесса загрузки.
Описание
Загружает асинхронно с диска файл сцены с последовательностью.
using System.Collections; using Unity.Collections; using Unity.Content; using Unity.Loading; using UnityEngine; using UnityEngine.SceneManagement;
public class SampleBehaviour : MonoBehaviour { public IEnumerator Start() { NativeArray<ContentFile> empty = new NativeArray<ContentFile>(); ContentFile depFileHandle = ContentLoadInterface.LoadContentFileAsync(ContentNamespace.Default, "path/to/depfile", empty);
var sceneParams = new ContentSceneParameters(); sceneParams.loadSceneMode = LoadSceneMode.Additive; sceneParams.localPhysicsMode = LocalPhysicsMode.None; sceneParams.autoIntegrate = false;
NativeArray<ContentFile> files = new NativeArray<ContentFile>(1, Allocator.Temp, NativeArrayOptions.ClearMemory); files[0] = depFileHandle; ContentSceneFile op = ContentLoadInterface.LoadSceneAsync(ContentNamespace.Default, "path/to/scene", "TestScene", sceneParams, files); files.Dispose();
// wait until the async loading process completes while (op.Status == SceneLoadingStatus.InProgress) yield return null;
op.IntegrateAtEndOfFrame();
// wait one frame yield return null;
// scene is now loaded and integrated ...
// unload scene op.UnloadAtEndOfFrame(); yield return null;
ContentFileUnloadHandle unloadHandleDep = depFileHandle.UnloadAsync();
while (!unloadHandleDep.IsCompleted) yield return null; } }