Exemplo n.º 1
0
    IEnumerator Start()
    {
        var LIST_DOWNLOAD_URL = "https://raw.githubusercontent.com/sassembla/Autoya/master/AssetBundles/main_assets/OSX/1.0.0/main_assets.json";
        var ASSET_NAME        = "Assets/AutoyaTests/RuntimeData/AssetBundles/MainResources/textureName.png";

        // Download AssetBundle List from web.
        var listDownloader = new AssetBundleListDownloader();

        AssetBundleList list = null;
        var             cor  = listDownloader.DownloadAssetBundleList(
            LIST_DOWNLOAD_URL,
            (url, newList) =>
        {
            list = newList;
        },
            (code, reason, status) =>
        {
            Debug.LogError("list download error, code:" + code + " reason:" + reason);
        }
            );

        while (cor.MoveNext())
        {
            yield return(null);
        }


        // Load Asset from your AssetBundle.
        var loader = new AssetBundleLoader(
            bundleName =>
        {
            var path = "https://raw.githubusercontent.com/sassembla/Autoya/master/AssetBundles/" +
                       list.identity + "/" +
                       list.target + "/" +
                       list.version + "/";
            return(path);
        }
            );

        // set list to AssetBundleLoader.
        loader.UpdateAssetBundleList(list);

        var loadCor = loader.LoadAsset <Texture2D>(
            ASSET_NAME,
            (name, tex) =>
        {
            Debug.Log("asset loaded! tex:" + tex);
        },
            (name, error, reason, status) =>
        {
            Debug.LogError("asset load failed. error:" + error + " reason:" + reason);
        }
            );

        while (loadCor.MoveNext())
        {
            yield return(null);
        }
    }
    public IEnumerator GetAssetBundleList()
    {
        var listPath       = abListPath + "1.0.0/main_assets.json";
        var listDownloader = new AssetBundleListDownloader();

        var done = false;

        yield return(listDownloader.DownloadAssetBundleList(
                         listPath,
                         (downloadedUrl, list) =>
        {
            done = true;
        },
                         (code, reason, autoyaStatus) =>
        {
            Fail("failed to get list." + code + " reason:" + reason);
            // do nothing.
        }
                         ));

        yield return(WaitUntil(
                         () => done, () => { throw new TimeoutException("not yet get assetBundleList."); }
                         ));
    }
    public IEnumerator GetAssetBundleListFailed()
    {
        var listPath = abListPath + "FAKEPATH";
        var loader   = new AssetBundleListDownloader();

        var done = false;

        yield return(loader.DownloadAssetBundleList(
                         listPath,
                         (downloadedUrl, list) =>
        {
            True(false, "should not be succeeded.");
        },
                         (code, reason, autoyaStatus) =>
        {
            True(code == 404, "error code does not match.");
            done = true;
        }
                         ));

        yield return(WaitUntil(
                         () => done, () => { throw new TimeoutException("not yet get assetBundleList."); }
                         ));
    }
        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
                        )
                    );
            }
        }
Exemplo n.º 5
0
        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
                        )
                    );
            }
        }