예제 #1
0
    public IEnumerator PreloadWithPreloadList()
    {
        var preloadBundleNames = loader.GetWholeBundleNames();
        var preloadList        = new PreloadList("PreloadWithPreloadList", preloadBundleNames);

        var doneCount = 0;

        yield return(assetBundlePreloader.Preload(
                         loader,
                         preloadList,
                         (willLoadBundleNames, proceed, cancel) =>
        {
            proceed();
        },
                         progress =>
        {
            doneCount++;
        },
                         () =>
        {
            // do nothng.
        },
                         (code, reason, autoyaStatus) =>
        {
            Debug.LogError("failed to download, code:" + code + " reason:" + reason);
        },
                         (preloadFailedAssetBundleName, code, reason, autoyaStatus) =>
        {
            Debug.LogError("failed to download, name:" + preloadFailedAssetBundleName + " code:" + code);
        }
                         ));

        WaitUntil(() => doneCount == preloadBundleNames.Length, () => { throw new TimeoutException("not yet done. doneCount:" + doneCount); });
    }
예제 #2
0
        /**
         *      download assetBundles by the preloadList, then download assetBundles.
         *      this feature will download "not downloaded" assetBundles only.
         *
         *      onBeforePreloading:
         *              you can set the Action to this param for getting "will be download assetBundles names".
         *              then if execute proceed(), download will be started.
         *              else, execute cancel(), download will be cancelled
         */
        public static void AssetBundle_PreloadByList(PreloadList preloadList, Action <string[], Action, Action> onBeforePreloading, Action <double> progress, Action done, Action <int, string, AutoyaStatus> preloadListDownloadFailed, Action <string, int, string, AutoyaStatus> bundleDownloadFailed, int maxParallelCount, double timeoutSec = 0)
        {
            var cont = CheckAssetBundlesFeatureCondition(
                (code, reason) => {
                preloadListDownloadFailed((int)code, reason, new AutoyaStatus());
            }
                );

            if (!cont)
            {
                return;
            }

            Action <AssetBundleLoader> act = loader => {
                autoya.mainthreadDispatcher.Commit(
                    autoya._assetBundlePreloader.Preload(
                        loader,
                        preloadList,
                        onBeforePreloading,
                        progress,
                        done,
                        preloadListDownloadFailed,
                        bundleDownloadFailed,
                        maxParallelCount
                        )
                    );
            };

            autoya.mainthreadDispatcher.Commit(
                autoya.PreloaderCoroutine(act, preloadListDownloadFailed)
                );
        }
예제 #3
0
    public IEnumerator PreloadAssetBundleWithGeneratedPreloadList()
    {
        yield return(GetAssetBundleList());

        var done = false;

        var lists          = Autoya.AssetBundle_AssetBundleLists();
        var mainAssetsList = lists.Where(list => list.identity == "main_assets").FirstOrDefault();

        NotNull(mainAssetsList);

        var preloadList = new PreloadList("test", mainAssetsList);

        // rewrite. set 1st content of bundleName.
        preloadList.bundleNames = new string[] { preloadList.bundleNames[0] };

        Autoya.AssetBundle_PreloadByList(
            preloadList,
            (willLoadBundleNames, proceed, cancel) =>
        {
            proceed();
        },
            progress =>
        {
        },
            () =>
        {
            done = true;
        },
            (code, reason, autoyaStatus) =>
        {
            Fail("should not be failed. code:" + code + " reason:" + reason);
        },
            (failedAssetBundleName, code, reason, autoyaStatus) =>
        {
        },
            1
            );

        yield return(WaitUntil(
                         () => done,
                         () => { throw new TimeoutException("not yet done."); }
                         ));
    }
예제 #4
0
    // 特定のjsonで記述された「アセットバンドル情報をまとめたリスト」をダウンロードするサンプル
    //
    IEnumerator Start()
    {
        /*
         *  this is sample of "preload assetBundles feature".
         *  the word "preload" in this sample means "download assetBundles without use."
         *  preloaded assetBundles are stored in storage cache. no difference between preloaded and downloaded assetBundles.
         *  case2:get preloadList from web, then get described assetBundles.
         */

        Autoya.AssetBundle_DownloadAssetBundleListsIfNeed(status => { }, (code, reason, autoyaStatus) => { });

        // wait downloading assetBundleList.
        while (!Autoya.AssetBundle_IsAssetBundleFeatureReady())
        {
            yield return(null);
        }

        var assetBundleLists = Autoya.AssetBundle_AssetBundleLists();

        // create sample preloadList which contains all assetBundle names in assetBundleList.
        var assetBundleNames = assetBundleLists.SelectMany(list => list.assetBundles).Select(abInfo => abInfo.bundleName).ToArray();
        var newPreloadList   = new PreloadList("samplePreloadList", assetBundleNames);

        Autoya.AssetBundle_PreloadByList(
            newPreloadList,
            (willLoadBundleNames, proceed, cancel) =>
        {
            proceed();
        },
            progress =>
        {
            Debug.Log("progress:" + progress);
        },
            () =>
        {
            Debug.Log("preloading all listed assetBundles is finished.");

            // then, you can use these assetBundles immediately. without any downloading.
            Autoya.AssetBundle_LoadAsset <GameObject>(
                "Assets/Demo/____ASSET_BUNDLES/unitychan_std/Prefabs/UnityChan_Std.prefab",
                (assetName, prefab) =>
            {
                Debug.Log("asset:" + assetName + " is successfully loaded as:" + prefab);

                // instantiate asset.
                Instantiate(prefab);
            },
                (assetName, err, reason, status) =>
            {
                Debug.LogError("failed to load assetName:" + assetName + " err:" + err + " reason:" + reason);
            }
                );

            Autoya.AssetBundle_LoadAsset <GameObject>(
                "Assets/Demo/____ASSET_BUNDLES/unitychan_crs/Prefabs/UnityChan_Crs.prefab",
                (assetName, prefab) =>
            {
                Debug.Log("asset:" + assetName + " is successfully loaded as:" + prefab);

                // instantiate asset.
                Instantiate(prefab, new Vector3(1f, 0, 0), Quaternion.identity);
            },
                (assetName, err, reason, status) =>
            {
                Debug.LogError("failed to load assetName:" + assetName + " err:" + err + " reason:" + reason);
            }
                );
        },
            (code, reason, autoyaStatus) =>
        {
            Debug.LogError("preload failed. code:" + code + " reason:" + reason);
        },
            (downloadFailedAssetBundleName, code, reason, autoyaStatus) =>
        {
            Debug.LogError("failed to preload assetBundle:" + downloadFailedAssetBundleName + ". code:" + code + " reason:" + reason);
        },
            10 // 10 parallel download! you can set more than 0.
            );
    }
예제 #5
0
    // Use this for initialization
    IEnumerator Start()
    {
        // need to wait finish authentication.
        while (!Autoya.Auth_IsAuthenticated())
        {
            yield return(null);
        }

        /*
         *              this is sample of "preload assetBundles feature".
         *
         *              the word "preload" in this sample means "download assetBundles without use."
         *              preloaded assetBundles are stored in storage cache. no difference between preloaded and downloaded assetBundles.
         *
         *              case1:generate preloadList from assetBundleList, then get described assetBundles.
         */

        Autoya.AssetBundle_DownloadAssetBundleListsIfNeed(status => { }, (code, reason, autoyaStatus) => { });

        // wait downloading assetBundleList.
        while (!Autoya.AssetBundle_IsAssetBundleFeatureReady())
        {
            yield return(null);
        }


        /*
         *              let's preload specific assetBundle into device storage.
         */

        // get assetBundleList.
        var assetBundleLists = Autoya.AssetBundle_AssetBundleLists();

        // create sample preloadList which contains all assetBundle names in assetBundleList.
        var assetBundleNames = assetBundleLists.SelectMany(list => list.assetBundles).Select(abInfo => abInfo.bundleName).ToArray();
        var newPreloadList   = new PreloadList("samplePreloadList", assetBundleNames);

        Autoya.AssetBundle_PreloadByList(
            newPreloadList,
            (willLoadBundleNames, proceed, cancel) =>
        {
            proceed();
        },
            progress =>
        {
            Debug.Log("progress:" + progress);
        },
            () =>
        {
            Debug.Log("preloading all listed assetBundles is finished.");

            // then, you can use these assetBundles immediately. without any downloading.
            Autoya.AssetBundle_LoadAsset <GameObject>(
                "Assets/AutoyaTests/RuntimeData/AssetBundles/MainResources/textureName1.prefab",
                (assetName, prefab) =>
            {
                Debug.Log("asset:" + assetName + " is successfully loaded as:" + prefab);

                // instantiate asset.
                Instantiate(prefab);
            },
                (assetName, err, reason, status) =>
            {
                Debug.LogError("failed to load assetName:" + assetName + " err:" + err + " reason:" + reason);
            }
                );
        },
            (code, reason, autoyaStatus) =>
        {
            Debug.LogError("preload failed. code:" + code + " reason:" + reason);
        },
            (downloadFailedAssetBundleName, code, reason, autoyaStatus) =>
        {
            Debug.LogError("failed to preload assetBundle:" + downloadFailedAssetBundleName + ". code:" + code + " reason:" + reason);
        },
            10 // 10 parallel download! you can set more than 0.
            );
    }
예제 #6
0
    public IEnumerator UpdateListWithOnMemoryAssetsThenPreloadLoadedChangedAsset()
    {
        var done = false;

        Autoya.AssetBundle_DownloadAssetBundleListsIfNeed(
            status =>
        {
            done = true;
        },
            (code, reason, asutoyaStatus) =>
        {
            Fail("UpdateListWithOnMemoryAssets failed, code:" + code + " reason:" + reason);
        }
            );

        yield return(WaitUntil(
                         () => done,
                         () => { throw new TimeoutException("faild to get assetBundleList."); }
                         ));

        True(Autoya.AssetBundle_IsAssetBundleFeatureReady());


        UnityEngine.Object[] loadedAssets = null;

        // 全てのABをロード
        yield return(LoadAllAssetBundlesOfMainAssets(objs => { loadedAssets = objs; }));

        True(loadedAssets != null);
        // var guids = loadedAssets.Select(a => a.GetInstanceID()).ToArray();

        var loadedAssetBundleNames = Autoya.AssetBundle_AssetBundleLists().Where(list => list.identity == "main_assets").FirstOrDefault().assetBundles.Select(a => a.bundleName).ToArray();

        // 1.0.1 リストの更新判断の関数をセット
        var listContainsUsingAssetsAndShouldBeUpdate = false;

        Autoya.Debug_SetOverridePoint_ShouldRequestNewAssetBundleList(
            (basePath, identity, ver) =>
        {
            var url = basePath + identity + "/" + AssetBundlesSettings.PLATFORM_STR + "/" + ver + "/" + identity + ".json";
            return(Autoya.ShouldRequestOrNot.Yes(url));
        }
            );

        Autoya.Debug_SetOverridePoint_ShouldUpdateToNewAssetBundleList(
            condition =>
        {
            if (condition == Autoya.CurrentUsingBundleCondition.UsingAssetsAreChanged)
            {
                listContainsUsingAssetsAndShouldBeUpdate = true;
            }
            return(true);
        }
            );



        // 1.0.1リストを取得
        Autoya.Http_Get(
            "https://httpbin.org/response-headers?" + AuthSettings.AUTH_RESPONSEHEADER_RESVERSION + "=main_assets:1.0.1",
            (conId, data) =>
        {
            // pass.
        },
            (conId, code, reason, status) =>
        {
            Fail();
        }
            );

        yield return(WaitUntil(
                         () => listContainsUsingAssetsAndShouldBeUpdate,
                         () => { throw new TimeoutException("failed to get response."); },
                         10
                         ));

        True(Autoya.AssetBundle_AssetBundleLists().Where(list => list.identity == "main_assets").FirstOrDefault().version == "1.0.1");


        // preload all.
        var preloadDone = false;

        var preloadList = new PreloadList("dummy", loadedAssetBundleNames);

        Autoya.AssetBundle_PreloadByList(
            preloadList,
            (preloadCandidateBundleNames, go, stop) =>
        {
            // all assetBundles should not be download. on memory loaded ABs are not updatable.
            True(preloadCandidateBundleNames.Length == 0);
            go();
        },
            progress => { },
            () =>
        {
            preloadDone = true;
        },
            (code, reason, status) =>
        {
            Fail("code:" + code + " reason:" + reason);
        },
            (failedAssetBundleName, code, reason, status) =>
        {
            Fail("failedAssetBundleName:" + failedAssetBundleName + " code:" + code + " reason:" + reason);
        },
            5
            );

        yield return(WaitUntil(
                         () => preloadDone,
                         () => { throw new TimeoutException("failed to preload."); },
                         10
                         ));
    }