// Token: 0x06005136 RID: 20790 RVA: 0x001BB62C File Offset: 0x001B9A2C
    private IEnumerator LoadAsyncCoroutine(AssetBundleDownload download)
    {
        if (download.currentState == AssetBundleDownload.State.Error)
        {
            yield break;
        }
        download.currentState = AssetBundleDownload.State.LoadingAssetFromAssetBundle;
        if (download.assetBundle != null)
        {
            string             mainAssetName = AssetBundleDownloadManager.GetMainAssetName(download.assetBundle);
            AssetBundleRequest asyncRequest  = null;
            UnityEngine.Object asset         = null;
            if (string.IsNullOrEmpty(mainAssetName))
            {
                VRC.Core.Logger.Log(string.Concat(new object[]
                {
                    "[",
                    download.downloadId,
                    "] Loading asset ",
                    download.assetUrl,
                    " synchronously."
                }), DebugLevel.AssetBundleDownloadManager);
                asset = download.assetBundle.mainAsset;
            }
            else
            {
                VRC.Core.Logger.Log(string.Concat(new object[]
                {
                    "[",
                    download.downloadId,
                    "] Loading asset ",
                    download.assetUrl,
                    " aynchronously."
                }), DebugLevel.AssetBundleDownloadManager);
                asyncRequest = download.assetBundle.LoadAssetWithSubAssetsAsync(mainAssetName);
                yield return(asyncRequest);

                asset = asyncRequest.asset;
            }
            if (asset != null)
            {
                AssetBundleDownloadManager.Instance.mLoadedAssets[download.assetUrl] = asset;
                download.asset        = asset;
                download.currentState = AssetBundleDownload.State.Done;
            }
            else
            {
                VRC.Core.Logger.Log("[" + download.downloadId + "] Error unpacking asset from asset bundle.", DebugLevel.AssetBundleDownloadManager);
                download.OnDownloadError("Error unpacking asset from asset bundle.", LoadErrorReason.AssetBundleInvalidOrNull);
            }
            VRC.Core.Logger.Log(string.Concat(new object[]
            {
                "[",
                download.downloadId,
                "] UNLOADING ASSET BUNDLE ",
                download.assetUrl
            }), DebugLevel.AssetBundleDownloadManager);
            download.assetBundle.Unload(false);
        }
        else
        {
            VRC.Core.Logger.Log(string.Concat(new object[]
            {
                "[",
                download.downloadId,
                "] Asset bundle for url ",
                download.assetUrl,
                " is invalid (and null)"
            }), DebugLevel.AssetBundleDownloadManager);
            download.OnDownloadError("LoadAsyncCoroutine: Asset bundle is null.", LoadErrorReason.AssetBundleInvalidOrNull);
        }
        yield break;
    }
Пример #2
0
    // Token: 0x06005BD3 RID: 23507 RVA: 0x002009DC File Offset: 0x001FEDDC
    public IEnumerator InstantiateDownloadedScene(AssetBundleDownload download, float timeLimit, Action onSuccess, Action <string> onError)
    {
        if (download == null)
        {
            Debug.LogError("Download was null");
            if (onError != null)
            {
                onError("Download was null");
            }
            yield break;
        }
        AssetBundle ab = download.assetBundle;

        if (ab == null)
        {
            Debug.LogError("Asset bundle did not load");
            if (onError != null)
            {
                onError("Asset bundle did not load");
            }
            yield break;
        }
        VRCAudioManager.EnableAllAudio(false);
        string[] sceneFiles = ab.GetAllScenePaths();
        if (sceneFiles.Length != 1)
        {
            Debug.LogWarning("VRCW file has bad scene count - " + download.assetUrl);
        }
        string sceneName = Path.GetFileNameWithoutExtension(sceneFiles[0]);

        Debug.Log("Loading scene: " + sceneName);
        AssetBundleDownloadManager.RegisterManuallyLoadedAssetBundle(download.assetUrl, ab, ab);
        bool loadLevelSuccess = false;

        yield return(AssetManagement.LoadLevelAsync(sceneName, LoadSceneMode.Single, timeLimit, delegate
        {
            loadLevelSuccess = true;
        }));

        if (!loadLevelSuccess)
        {
            Debug.LogError("Failed to load scene " + sceneName + ", LoadLevelAsync failed");
            if (onError != null)
            {
                onError("Failed to load scene " + sceneName + ", LoadLevelAsync failed");
            }
            yield break;
        }
        Scene scene = SceneManager.GetSceneByName(sceneName);

        if (!scene.isLoaded)
        {
            Debug.LogError("Failed to load scene " + sceneName);
            if (onError != null)
            {
                onError("Failed to load scene " + sceneName);
            }
            yield break;
        }
        if (!this.ProcessSceneObjectsImmediate())
        {
            Debug.LogError("Error processing scene objects post load");
            if (onError != null)
            {
                onError("Error processing scene objects post load, scene " + sceneName);
            }
            yield break;
        }
        yield return(null);

        yield return(null);

        SceneManager.SetActiveScene(scene);
        yield return(null);

        onSuccess();
        yield break;
    }