Exemple #1
0
        private IEnumerator get()
        {
            ICPipeManifestService cpipeManifestService  = Service.Get <ICPipeManifestService>();
            CPipeManifestResponse cpipeManifestResponse = new CPipeManifestResponse();

            yield return(cpipeManifestService.LookupAssetUrl(cpipeManifestResponse, contentPath));

            if (string.IsNullOrEmpty(cpipeManifestResponse.FullAssetUrl))
            {
                Log.LogErrorFormatted(this, "ERROR: CdnGet - contentPath '{0}' NOT FOUND!", contentPath);
                yield break;
            }
            switch (mode)
            {
            case ModeEnum.GetString:
                yield return(getString(cpipeManifestResponse.FullAssetUrl));

                break;

            case ModeEnum.GetFile:
                yield return(getFile(cpipeManifestResponse.FullAssetUrl));

                break;
            }
        }
        private IEnumerator contentManifest_download(ContentManifestDirectoryEntry directoryEntry)
        {
            if (directoryEntry == null)
            {
                handleFailure();
                yield break;
            }
            if (string.IsNullOrEmpty(directoryEntry.url))
            {
                handleFailure();
                yield break;
            }
            string contentManifestUrl = directoryEntry.url;
            ICPipeManifestService cpipeManifestService  = Service.Get <ICPipeManifestService>();
            CPipeManifestResponse cpipeManifestResponse = new CPipeManifestResponse();

            yield return(cpipeManifestService.LookupAssetUrl(cpipeManifestResponse, contentManifestUrl));

            UnityWebRequest www = UnityWebRequest.GetAssetBundle(cpipeManifestResponse.FullAssetUrl, 1u, 0u);

            Service.Get <LoadingController>().RegisterDownload(www);
            yield return(www.SendWebRequest());

            Service.Get <LoadingController>().UnRegisterDownload(www);
            AssetBundle contentBundle = ((DownloadHandlerAssetBundle)www.downloadHandler).assetBundle;

            if (www.isNetworkError || contentBundle == null)
            {
                Log.LogErrorFormatted(this, "Failed to download content bundle from CDN: {0}", www.error);
                handleFailure();
                yield break;
            }
            downloadedManifest = ContentHelper.GetContentManifestFromAssetBundle(contentBundle);
            if (downloadedManifest != null)
            {
                checkContentVersionAndManifestHashInManifest(downloadedManifest, directoryEntry);
                contentManifest_cacheDownloadedToDisk(downloadedManifest);
            }
            string[] assetNames = contentBundle.GetAllAssetNames();
            for (int i = 0; i < assetNames.Length; i++)
            {
                string fileName = Path.GetFileName(assetNames[i]);
                if (string.Equals(fileName, "ScenesPrereqBundlesManifest.json", StringComparison.OrdinalIgnoreCase))
                {
                    TextAsset textAsset = contentBundle.LoadAsset <TextAsset>(assetNames[i]);
                    scenePrereqBundlesManifest = Service.Get <JsonService>().Deserialize <ScenePrereqContentBundlesManifest>(textAsset.text);
                    scenePrereqBundlesManifest_cacheDownloadedToDisk(scenePrereqBundlesManifest);
                }
            }
            contentBundle.Unload(unloadAllLoadedObjects: false);
            if (downloadedManifest == null)
            {
                Log.LogError(this, "Content manifest not found in downloaded bundle! Reverting to the embedded manifest");
                handleFailure();
            }
        }
        public IEnumerator manifestDirectory_download()
        {
            ICPipeManifestService cpipeManifestService  = Service.Get <ICPipeManifestService>();
            CPipeManifestResponse cpipeManifestResponse = new CPipeManifestResponse();

            yield return(cpipeManifestService.LookupAssetUrl(cpipeManifestResponse, "ClientManifestDirectory.json"));

            bool   forceDownload = false;
            Uri    uri           = new Uri(cpipeManifestResponse.FullAssetUrl);
            string manifestDirectory_cachedPath = PathUtil.Combine(Application.persistentDataPath, uri.LocalPath);

            if (!forceDownload && File.Exists(manifestDirectory_cachedPath))
            {
                string stringToDeserialize = File.ReadAllText(manifestDirectory_cachedPath);
                manifestDirectory = Service.Get <JsonService>().Deserialize <ContentManifestDirectory>(stringToDeserialize);
                yield break;
            }
            UnityWebRequest www = UnityWebRequest.Get(cpipeManifestResponse.FullAssetUrl);

            Service.Get <LoadingController>().RegisterDownload(www);
            yield return(www.SendWebRequest());

            Service.Get <LoadingController>().UnRegisterDownload(www);
            try
            {
                if (www.isNetworkError || string.IsNullOrEmpty(www.downloadHandler.text))
                {
                    throw new Exception("Failed to download manifest directory from CDN. Reverting to the embedded directory.");
                }
                manifestDirectory = Service.Get <JsonService>().Deserialize <ContentManifestDirectory>(www.downloadHandler.text);
                string parentPath = PathUtil.GetParentPath(manifestDirectory_cachedPath);
                if (!Directory.Exists(parentPath))
                {
                    Directory.CreateDirectory(parentPath);
                }
                File.WriteAllText(manifestDirectory_cachedPath, www.downloadHandler.text);
            }
            catch (Exception)
            {
                manifestDirectory = manifestDirectory_loadEmbedded();
                onInitializeComplete(manifestService.LoadEmbeddedManifest());
            }
        }
        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();
        }