public override AssetRequest <TAsset> LoadAsync <TAsset>(string deviceList, ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null)
        {
            gcsAccessTokenService = Service.Get <IGcsAccessTokenService>();
            string bundlePath = UriUtil.Combine(baseUri, entry.Key);
            AssetBundleWwwWrapper          assetBundleWwwWrapper = new AssetBundleWwwWrapper(bundlePath, gcsAccessTokenService);
            AsyncBundleWwwRequest <TAsset> result = new AsyncBundleWwwRequest <TAsset>(entry.Key, assetBundleWwwWrapper);

            CoroutineRunner.StartPersistent(waitForBundleToLoad(assetBundleWwwWrapper, handler, entry.IsCacheOnly), this, "Local_waitForBundleToLoad");
            return(result);
        }
示例#2
0
        public override AssetRequest <TAsset> LoadAsync <TAsset>(string deviceList, ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null)
        {
            string bundlePath = UriUtil.Combine(baseUri, entry.Key);
            AssetBundleWwwWrapper          assetBundleWwwWrapper = new AssetBundleWwwWrapper(bundlePath, gcsAccessTokenService);
            AsyncBundleWwwRequest <TAsset> result = new AsyncBundleWwwRequest <TAsset>(entry.Key, assetBundleWwwWrapper);
            uint result2 = 0u;

            if (entry.UserData != null && entry.UserData is ContentManifest.BundleEntry && !uint.TryParse(((ContentManifest.BundleEntry)entry.UserData).Crc, out result2))
            {
                result2 = 0u;
            }
            CoroutineRunner.StartPersistent(waitForBundleToLoad(assetBundleWwwWrapper, result2, handler), this, "waitForBundleToLoad");
            return(result);
        }
        private IEnumerator waitForBundleToLoad <TAsset>(AssetBundleWwwWrapper bundleRequest, AssetLoadedHandler <TAsset> handler, bool cacheOnly) where TAsset : class
        {
            bundleRequest.LoadFromDownload(bundleRequest.BundlePath);
            Service.Get <LoadingController>().RegisterDownload(bundleRequest.WebRequest);
            yield return(bundleRequest.Send());

            Service.Get <LoadingController>().UnRegisterDownload(bundleRequest.WebRequest);
            if (handler != null)
            {
                AssetBundle assetBundle = null;
                if (!cacheOnly)
                {
                    assetBundle = bundleRequest.AssetBundle;
                }
                TAsset asset = null;
                if (assetBundle != null)
                {
                    asset = (TAsset)(object)assetBundle;
                }
                handler(bundleRequest.BundlePath, asset);
            }
            yield return(null);
        }
示例#4
0
        private IEnumerator waitForBundleToLoad <TAsset>(AssetBundleWwwWrapper bundleRequestWrapper, uint crc, AssetLoadedHandler <TAsset> handler) where TAsset : class
        {
            CPipeManifestResponse cpipeManifestResponse = new CPipeManifestResponse();

            yield return(cpipeManifestService.LookupAssetUrl(cpipeManifestResponse, bundleRequestWrapper.BundlePath));

            if (string.IsNullOrEmpty(cpipeManifestResponse.FullAssetUrl))
            {
                throw new Exception($"Bundle \"{bundleRequestWrapper.BundlePath}\" NOT FOUND in CPipe manifest.");
            }
            while (!Caching.ready)
            {
                yield return(null);
            }
            bundleRequestWrapper.LoadFromCacheOrDownload(cpipeManifestResponse.FullAssetUrl, crc);
            Service.Get <LoadingController>().RegisterDownload(bundleRequestWrapper.WebRequest);
            yield return(bundleRequestWrapper.Send());

            Service.Get <LoadingController>().UnRegisterDownload(bundleRequestWrapper.WebRequest);
            if (DelayLoading)
            {
                yield return(null);

                yield return(null);
            }
            for (int i = 0; i < 3; i++)
            {
                if (bundleRequestWrapper.WebRequest.isNetworkError)
                {
                    Log.LogErrorFormatted(this, "Retry count {0}. Failed to download bundle {1} with error: {2}", i + 1, bundleRequestWrapper.BundlePath, bundleRequestWrapper.WebRequest.error);
                }
                else
                {
                    if (!(bundleRequestWrapper.AssetBundle == null))
                    {
                        break;
                    }
                    Log.LogErrorFormatted(this, "Retry count {0}. Downloaded bundle was null", i + 1);
                }
                bundleRequestWrapper.LoadFromCacheOrDownload(cpipeManifestResponse.FullAssetUrl, crc);
                string message = $"Retry bundle load with expected CRC {crc}: {bundleRequestWrapper.BundlePath}";
                Crittercism.LeaveBreadcrumb(message);
                Service.Get <LoadingController>().RegisterDownload(bundleRequestWrapper.WebRequest);
                yield return(bundleRequestWrapper.Send());

                Service.Get <LoadingController>().UnRegisterDownload(bundleRequestWrapper.WebRequest);
            }
            if (bundleRequestWrapper.AssetBundle != null)
            {
                string breadcrumb = $"Loaded bundle with expected CRC {crc}: {bundleRequestWrapper.BundlePath}";
                Crittercism.LeaveBreadcrumb(breadcrumb);
            }
            else
            {
                string breadcrumb = $"Failed to load bundle with expected CRC {crc}: {bundleRequestWrapper.BundlePath}";
                Crittercism.LeaveBreadcrumb(breadcrumb);
            }
            if (handler != null)
            {
                TAsset asset = null;
                if (bundleRequestWrapper.AssetBundle != null)
                {
                    asset = (TAsset)(object)bundleRequestWrapper.AssetBundle;
                }
                handler(bundleRequestWrapper.BundlePath, asset);
            }
            bundleRequestWrapper.IsComplete = true;
            bundleRequestWrapper.CacheAndDispose();
        }