Exemple #1
0
 private IEnumerator ListLoaderCoroutine(Action execute)
 {
     // start loading.
     assetBundleFeatState = AssetBundlesFeatureState.ListLoading;
     execute();
     yield break;
 }
Exemple #2
0
        /*
         *      Initializer
         */
        private void InitializeAssetBundleFeature()
        {
            // initialize AssetBundleListDownloader.
            AssetBundleListDownloader.HttpResponseHandlingDelegate httpResponseHandlingDel = (p1, p2, p3, p4, p5, p6, p7) => {
                httpResponseHandlingDelegate(p1, p2, p3, p4, p5, p6, p7);
            };
            AssetBundleListDownloader.AssetBundleListGetRequestHeaderDelegate assetBundleGetRequestHeaderDel = (p1, p2) => {
                return(assetBundleListGetRequestHeaderDelegate(p1, p2));
            };

            _assetBundleListDownloader = new AssetBundleListDownloader(assetBundleGetRequestHeaderDel, httpResponseHandlingDel);

            // check if assetBundleList are stored.
            var listCandidate = LoadAssetBundleListFromStorage();

            if (!listCandidate.Exists())
            {
                // no list stored.
                assetBundleFeatState = AssetBundlesFeatureState.None;
                return;
            }

            _currentAssetBundleList = listCandidate;
            assetBundleFeatState    = AssetBundlesFeatureState.Ready;
            ReadyLoaderAndPreloader();
        }
        /*
			Initializer
		 */
        private void InitializeAssetBundleFeature()
        {
            // initialize AssetBundleListDownloader.
            AssetBundleListDownloader.HttpResponseHandlingDelegate httpResponseHandlingDel = (p1, p2, p3, p4, p5, p6, p7) =>
            {
                httpResponseHandlingDelegate(p1, p2, p3, p4, p5, p6, p7);
            };
            AssetBundleListDownloader.AssetBundleListGetRequestHeaderDelegate assetBundleGetRequestHeaderDel = (p1, p2) =>
            {
                return assetBundleListGetRequestHeaderDelegate(p1, p2);
            };

            /*
                by default, only list downloader is ready on boot in AssetBundles feature.
             */
            _assetBundleListDownloader = new AssetBundleListDownloader(assetBundleGetRequestHeaderDel, httpResponseHandlingDel);

            // check if assetBundleList are stored.
            var storedLists = LoadAssetBundleListsFromStorage();
            var storedListIdentities = storedLists.Select(list => list.identity).ToArray();

            // get assetBundleList identitiy from manifest info.
            var runtimeManifestContaindAssetBundleListIdentities = LoadAppUsingAssetBundleListIdentities();


            // 取得失敗などでmanifestの内容の方が多いことがあり得る。差を取り出し、DLが必要な状態かどうか判断する。
            var excepts = runtimeManifestContaindAssetBundleListIdentities.Except(storedListIdentities);

            // not all assetBundleList are stored yet.
            // need to run AssetBundle_DownloadAssetBundleListsIfNeed().
            if (excepts.Any())
            {
                assetBundleFeatState = AssetBundlesFeatureState.None;
                return;
            }

            // all assetBundleList is stored and ready.
            foreach (var listCandidate in storedLists)
            {
                ReadyLoaderAndPreloader(listCandidate);
            }
            assetBundleFeatState = AssetBundlesFeatureState.Ready;
        }
        /*
         *              Initializer
         */
        private IEnumerator InitializeAssetBundleFeature()
        {
            this.assetBundleListGetRequestHeaderDelegate        = OnAssetBundleListGetRequest;
            this.assetBundlePreloadListGetRequestHeaderDelegate = OnAssetBundlePreloadListGetRequest;
            this.assetBundleGetRequestHeaderDelegate            = OnAssetBundleGetRequest;

            // initialize AssetBundleListDownloader.
            AssetBundleListDownloader.HttpResponseHandlingDelegate httpResponseHandlingDel = (p1, p2, p3, p4, p5, p6, p7) =>
            {
                httpResponseHandlingDelegate(p1, p2, p3, p4, p5, p6, p7);
            };
            AssetBundleListDownloader.AssetBundleListGetRequestHeaderDelegate assetBundleGetRequestHeaderDel = (p1, p2) =>
            {
                return(assetBundleListGetRequestHeaderDelegate(p1, p2));
            };

            /*
             *  by default, only list downloader is ready on boot in AssetBundles feature.
             */
            _assetBundleListDownloader = new AssetBundleListDownloader(assetBundleGetRequestHeaderDel, httpResponseHandlingDel);

            // check if assetBundleList are stored.
            var storedLists          = LoadAssetBundleListsFromStorage();
            var storedListIdentities = storedLists.Select(list => list.identity).ToArray();

            // get assetBundleList identitiy from manifest info.
            var runtimeManifestContaindAssetBundleListIdentities = LoadAppUsingAssetBundleListIdentities();

            // remove unnecessary stored ABList if runtimeManifest is changed and ABListInfo is removed.
            {
                var storedMinusManifest = storedListIdentities.Except(runtimeManifestContaindAssetBundleListIdentities);

                if (storedMinusManifest.Any())
                {
                    OnRemoveUnnecessaryAssetBundleListsFromStorage(storedMinusManifest.ToArray());

                    // renew stored list identities.
                    storedLists          = LoadAssetBundleListsFromStorage();
                    storedListIdentities = storedLists.Select(list => list.identity).ToArray();
                }
            }

            // check stored ABList. if less than required by RuntimeManifest, need to download additional ABList.
            {
                var manifestMinusStored = runtimeManifestContaindAssetBundleListIdentities.Except(storedListIdentities);

                // not all assetBundleList are stored yet.
                // need to run AssetBundle_DownloadAssetBundleListsIfNeed().
                if (manifestMinusStored.Any())
                {
                    assetBundleFeatState = AssetBundlesFeatureState.None;
                    yield break;
                }
            }

            // all assetBundleList is stored and ready.
            foreach (var listCandidate in storedLists)
            {
                ReadyLoaderAndPreloader(listCandidate);
            }
            assetBundleFeatState = AssetBundlesFeatureState.Ready;
        }
        private void Internal_AssetBundle_DownloadAssetBundleListFromUrl(string[] listUrls, Action <ListDownloadResult> downloadSucceeded, Action <ListDownloadErrorAndCode, string, AutoyaStatus> downloadFailed, double timeoutSec = AssetBundlesSettings.TIMEOUT_SEC)
        {
            assetBundleFeatState = AssetBundlesFeatureState.ListDownoading;

            var wholeAssetBundleListCount = listUrls.Length;

            var isDownloadFailed = false;

            var downloadedListIdentities = new List <string>();
            Action <string, AssetBundleList> succeeded = (url, newList) =>
            {
                /*
                 *  リストの保存に失敗した場合、全ての処理が失敗した扱いになる。
                 */
                var result = StoreAssetBundleListToStorage(newList);
                if (result)
                {
                    // update runtime manifest. set "resVersion" to downloaded version.
                    // update AssetBundleList version.
                    OnUpdateToNewAssetBundleList(newList.identity, newList.version);

                    try
                    {
                        // update list in loader.
                        ReadyLoaderAndPreloader(newList);
                    }
                    catch (Exception e)
                    {
                        assetBundleFeatState = AssetBundlesFeatureState.Ready;
                        downloadFailed(new ListDownloadErrorAndCode(ListDownloadError.NotCointainedInRuntimeManifestOrOther, 0), e.ToString(), new AutoyaStatus());
                        return;
                    }

                    downloadedListIdentities.Add(newList.identity);
                    if (downloadedListIdentities.Count == wholeAssetBundleListCount)
                    {
                        // set state to loaded.
                        assetBundleFeatState = AssetBundlesFeatureState.Ready;

                        // fire downloaded.
                        downloadSucceeded(ListDownloadResult.ListDownloaded);
                    }
                }
                else
                {
                    if (isDownloadFailed)
                    {
                        return;
                    }
                    isDownloadFailed = true;
                    downloadFailed(new ListDownloadErrorAndCode(ListDownloadError.FailedToStoreDownloadedAssetBundleList, 0), "failed to store assetBundleList info to device. downloaded list identity:" + newList.identity, new AutoyaStatus());
                }
            };


            foreach (var listUrl in listUrls)
            {
                /*
                 *  どれか一件でも失敗したら、リスト機構の初期化に失敗する。
                 */
                Action <int, string, AutoyaStatus> failed = (code, reason, autoyaStatus) =>
                {
                    if (isDownloadFailed)
                    {
                        return;
                    }
                    isDownloadFailed = true;

                    assetBundleFeatState = AssetBundlesFeatureState.None;
                    downloadFailed(new ListDownloadErrorAndCode(ListDownloadError.FailedToDownload, code), reason + " url:" + listUrl, autoyaStatus);
                };

                // parallel.
                mainthreadDispatcher.Commit(
                    _assetBundleListDownloader.DownloadAssetBundleList(
                        listUrl,
                        succeeded,
                        failed,
                        timeoutSec
                        )
                    );
            }
        }
        private void Internal_AssetBundle_DownloadAssetBundleListFromUrl(string[] listUrls, Action <ListDownloadResult> downloadSucceeded, Action <ListDownloadError, string, AutoyaStatus> downloadFailed, double timeoutSec = AssetBundlesSettings.TIMEOUT_SEC)
        {
            assetBundleFeatState = AssetBundlesFeatureState.ListDownoading;

            var wholeAssetBundleListCount = listUrls.Length;

            var isDownloadFailed = false;

            var downloadedListIdentities       = new List <string>();
            Action <AssetBundleList> succeeded = newList =>
            {
                /**
                 *  リストの保存に失敗した場合、全ての処理が失敗した扱いになる。
                 */
                var result = StoreAssetBundleListToStorage(newList);
                if (result)
                {
                    // update runtime manifest. set "resVersion" to downloaded version.
                    {
                        var newListIdentity = newList.identity;
                        var runtimeManifest = Autoya.Manifest_LoadRuntimeManifest();
                        foreach (var resInfo in runtimeManifest.resourceInfos)
                        {
                            if (resInfo.listIdentity == newListIdentity)
                            {
                                resInfo.listVersion = newList.version;
                                break;
                            }
                        }
                        Autoya.Manifest_UpdateRuntimeManifest(runtimeManifest);
                    }

                    // update list in loader.
                    ReadyLoaderAndPreloader(newList);

                    downloadedListIdentities.Add(newList.identity);
                    if (downloadedListIdentities.Count == wholeAssetBundleListCount)
                    {
                        // set state to loaded.
                        autoya.assetBundleFeatState = AssetBundlesFeatureState.Ready;

                        // fire downloaded.
                        downloadSucceeded(ListDownloadResult.ListDownloaded);
                    }
                }
                else
                {
                    if (isDownloadFailed)
                    {
                        return;
                    }
                    isDownloadFailed = true;
                    downloadFailed(ListDownloadError.FailedToStoreDownloadedAssetBundleList, "failed to store assetBundleList info to device. downloaded list identity:" + newList.identity, new AutoyaStatus());
                }
            };


            foreach (var listUrl in listUrls)
            {
                /*
                 *  どれか一件でも失敗したら、リスト機構の初期化に失敗する。
                 */
                Action <int, string, AutoyaStatus> failed = (code, reason, autoyaStatus) =>
                {
                    if (isDownloadFailed)
                    {
                        return;
                    }
                    isDownloadFailed = true;

                    assetBundleFeatState = AssetBundlesFeatureState.None;
                    downloadFailed(ListDownloadError.FailedToDownload, "code:" + code + " reason:" + reason + " url:" + listUrl, autoyaStatus);
                };

                // parallel.
                mainthreadDispatcher.Commit(
                    _assetBundleListDownloader.DownloadAssetBundleList(
                        listUrl,
                        succeeded,
                        failed,
                        timeoutSec
                        )
                    );
            }
        }