private IEnumerator DownloadBundlesRoutine()
    {
        for (int i = 0; i < DLCManager.Instance.toDownload.Count; i++)
        {
            DLCBundle bundle = DLCManager.Instance.toDownload[i];
            Debug.Log("Start downloading bundle: " + bundle.ToString());

            UnityWebRequest r = DLCManager.Instance.DownloadBundleRequest(bundle);
            UnityWebRequestAsyncOperation op = r.SendWebRequest();

            asyncOperations.Add(op);
        }

        while (asyncOperations.Where(x => !x.isDone).Count() > 0)
        {
            string text = "";
            for (int i = 0; i < asyncOperations.Count; i++)
            {
                text += "" + asyncOperations[i].priority + " - " + DLCManager.Instance.toDownload[i].name + ": " + asyncOperations[i].progress + " \n";
            }

            toDownloadText.text = text;
            yield return(new WaitForSeconds(1f));
        }

        for (int i = 0; i < DLCManager.Instance.toDownload.Count; i++)
        {
            UnityWebRequestAsyncOperation op = asyncOperations[i];

            if (op.webRequest.isHttpError)
            {
                Debug.Log("HTTP Error for: " + op.webRequest.url + " " + op.webRequest.error);
            }
            else if (op.webRequest.isNetworkError)
            {
                Debug.Log("NetworkError for: " + op.webRequest.url + " " + op.webRequest.error);
            }
            else
            {
                Debug.Log("Succes for: " + op.webRequest.url);
            }

            Debug.Log("Finalizing request!");
            yield return(StartCoroutine(DLCManager.Instance.FinalizeDownloadRequest(op.webRequest, DLCManager.Instance.toDownload[i])));
        }

        Debug.Log("Finished!");
    }
Esempio n. 2
0
        private IEnumerator LocationsFromAssetBundle(DLCBundle bundle)
        {
            AssetBundleCreateRequest loadBundleRequest = AssetBundle.LoadFromFileAsync(bundle.path);

            yield return(loadBundleRequest);

            if (loadBundleRequest.assetBundle == null)
            {
                AnalyticsService.Instance.LogEvent(AnalyticsService.EventType.Error, new Dictionary <string, object> {
                    { "msg", "couldn't load assetbundle: " + bundle.path }
                });
                yield break;
            }

            AssetBundle b = loadBundleRequest.assetBundle;
            List <GeoGuesserLocation> newLocations;

            try
            {
                TextAsset meta = b.LoadAsset <TextAsset>(settings_filename);
                newLocations = JsonConvert.DeserializeObject <List <GeoGuesserLocation> >(meta.text);
            }
            catch (Exception e)
            {
                AnalyticsService.Instance.LogEvent(AnalyticsService.EventType.Error, new Dictionary <string, object> {
                    { "msg", "couldn't read json for " + bundle.name + ": " + e.Message }
                });
                yield break;
            }

            foreach (GeoGuesserLocation l in newLocations)
            {
                AssetBundleRequest bundleRequest = b.LoadAssetAsync <Texture2D>(l.filename);
                yield return(bundleRequest);

                l.texture = (Texture2D)bundleRequest.asset;
            }
            b.Unload(false);

            geoGuesserLocations.AddRange(newLocations);
        }