Пример #1
0
        private ContentManifest contentManifest_loadEmbedded()
        {
            ContentManifestDirectory      contentManifestDirectory      = manifestDirectory_loadEmbedded();
            ContentManifestDirectoryEntry contentManifestDirectoryEntry = contentManifestDirectory.FindEmbeddedEntry(contentDate, clientApiVersionStr, clientPlatform);

            if (contentManifestDirectoryEntry == null)
            {
                object[]       array          = new object[3];
                DateTimeOffset dateTimeOffset = contentDate;
                array[0] = dateTimeOffset.ToString();
                array[1] = clientApiVersionStr;
                array[2] = clientPlatform;
                Log.LogErrorFormatted(this, "contentManifest_loadEmbedded(): unable to FindEmbeddedEntry for {0}, {1}, {2}", array);
            }
            return(new ContentManifest(Resources.Load <TextAsset>(contentManifestDirectoryEntry.url)));
        }
        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());
            }
        }