Ejemplo n.º 1
0
    public IEnumerator ReceiveUpdatedListThenIgnoreAndIgnoredListIsCached()
    {
        var done = false;

        Autoya.Debug_AssetBundle_DownloadAssetBundleListFromUrl(
            abListPath + "main_assets/" + AssetBundlesSettings.PLATFORM_STR + "/1.0.0/main_assets.json",
            status =>
        {
            done = true;
        },
            (code, reason, autoyaStatus) =>
        {
            // do nothing.
        }
            );

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

        // リスト1.0.0が保持されている。
        // 通信のレスポンスヘッダーに特定の値が含まれていることで、listの更新リクエストを送り出す機構を着火する。


        // 新しいリストの取得判断の関数をセット(レスポンスを捕まえられるはず)
        Autoya.Debug_SetOverridePoint_ShouldRequestNewAssetBundleList(
            (basePath, identity, newVersion) =>
        {
            True(newVersion == "1.0.1");
            return(RequestYes(basePath, identity, newVersion));
        }
            );

        // リストの更新判断の関数をセット、ここでは更新を無視する。
        // 無視されたリストはpostponedなリストとしてメモリ上に保持される。これによって無駄な取得リクエストを省く。
        var listWillBeIgnored = false;

        Autoya.Debug_SetOverridePoint_ShouldUpdateToNewAssetBundleList(
            condition =>
        {
            listWillBeIgnored = true;
            return(false);
        }
            );


        Autoya.Http_Get(
            "https://httpbin.org/response-headers?" + resversionDesc + "=main_assets:1.0.1",
            (conId, data) =>
        {
            // pass.
        },
            (conId, code, reason, status) =>
        {
            Fail();
        }
            );

        yield return(WaitUntil(
                         () => listWillBeIgnored,
                         () => { throw new TimeoutException("too late."); }
                         ));

        // list is not updated yet.
        True(Autoya.AssetBundle_AssetBundleLists()[0].version == "1.0.0");

        True(Autoya.Debug_AssetBundle_FeatureState() == Autoya.AssetBundlesFeatureState.Ready);

        // set to the new list to be updated.
        var listWillBeUpdated = false;

        Autoya.Debug_SetOverridePoint_ShouldUpdateToNewAssetBundleList(
            condition =>
        {
            listWillBeUpdated = true;
            return(true);
        }
            );

        // get list again.
        Autoya.Http_Get(
            "https://httpbin.org/response-headers?" + resversionDesc + "=main_assets:1.0.1",
            (conId, data) =>
        {
            // pass.
        },
            (conId, code, reason, status) =>
        {
            Fail();
        }
            );

        yield return(WaitUntil(
                         () => listWillBeUpdated,
                         () => { throw new TimeoutException("too late."); }
                         ));

        True(Autoya.AssetBundle_AssetBundleLists()[0].version == "1.0.1");
    }
Ejemplo n.º 2
0
    public IEnumerator ReceiveUpdatedListThenOnAssetBundleListUpdatedFired()
    {
        var done = false;
        Autoya.AssetBundle_DownloadAssetBundleListFromUrlManually(
            abListPath + "main_assets/" + AssetBundlesSettings.PLATFORM_STR + "/1.0.0/main_assets.json",
            status =>
            {
                done = true;
            },
            (code, reason, autoyaStatus) =>
            {
                // do nothing.
            }
        );

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

        // リスト1.0.0が保持されている。
        // 通信のレスポンスヘッダーに特定の値が含まれていることで、listの更新リクエストを送り出す機構を着火する。


        // 新しいリストの取得判断の関数をセット(レスポンスを捕まえられるはず)
        Autoya.Debug_SetOverridePoint_ShouldRequestNewAssetBundleList(
            (identity, newVersion) =>
            {
                True(newVersion == "1.0.1");
                return RequestYes(identity, newVersion);
            }
        );

        // リストの更新判断の関数をセット
        var isListUpdated = false;
        Autoya.Debug_SetOverridePoint_ShouldUpdateToNewAssetBundleList(
            (condition, proceed, cancel) =>
            {
                proceed();
            }
        );

        Autoya.Debug_SetOnOverridePoint_OnAssetBundleListUpdated(
            (newVersion, ready) =>
            {
                ready();
                isListUpdated = true;
            }
        );


        Autoya.Http_Get(
            "https://httpbin.org/response-headers?" + resversionDesc + "=main_assets:1.0.1",
            (conId, data) =>
            {
                // pass.
            },
            (conId, code, reason, status) =>
            {
                Fail();
            }
        );

        yield return WaitUntil(
            () => isListUpdated,
            () => { throw new TimeoutException("too late."); }
        );

        // list is updated.
        True(Autoya.AssetBundle_AssetBundleLists()[0].version == "1.0.1");

        True(Autoya.Debug_AssetBundle_FeatureState() == Autoya.AssetBundlesFeatureState.Ready);
    }
Ejemplo n.º 3
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
                         ));
    }
Ejemplo n.º 4
0
    public IEnumerator UpdateListWithOnMemoryAssetsThenReloadChangedAsset()
    {
        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 guidsDict = loadedAssets.ToDictionary(
            a => a.name,
            a => a.GetInstanceID()
            );

        // 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("code:" + code + " reason:" + reason);
        }
            );

        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");

        // 再度ロード済みのAssetをLoadしようとすると、更新があったABについて最新を取得してくる。

        UnityEngine.Object[] loadedAssets2 = null;
        yield return(LoadAllAssetBundlesOfMainAssets(objs => { loadedAssets2 = objs; }));

        var newGuidsDict = loadedAssets2.ToDictionary(
            a => a.name,
            a => a.GetInstanceID()
            );

        var changedAssetCount = 0;

        foreach (var newGuidItem in newGuidsDict)
        {
            var name = newGuidItem.Key;
            var guid = newGuidItem.Value;
            if (guidsDict[name] != guid)
            {
                changedAssetCount++;
            }
        }
        True(changedAssetCount == 1);
    }
Ejemplo n.º 5
0
    public IEnumerator UpdateListWithOnMemoryAssets()
    {
        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);

        // 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");

        // load状態のAssetはそのまま使用できる
        for (var i = 0; i < loadedAssets.Length; i++)
        {
            var loadedAsset = loadedAssets[i];
            True(loadedAsset != null);
        }
    }
Ejemplo n.º 6
0
    private IEnumerator LoadAllAssetBundlesOfMainAssets(Action <UnityEngine.Object[]> onLoaded)
    {
        var bundles = Autoya.AssetBundle_AssetBundleLists().Where(list => list.identity == "main_assets").FirstOrDefault().assetBundles;

        var loaded        = 0;
        var allAssetCount = bundles.Sum(s => s.assetNames.Length);

        True(0 < allAssetCount, "allAssetCount:" + allAssetCount);

        var loadedAssets = new UnityEngine.Object[allAssetCount];

        foreach (var bundle in bundles)
        {
            foreach (var assetName in bundle.assetNames)
            {
                if (assetName.EndsWith(".png"))
                {
                    Autoya.AssetBundle_LoadAsset(
                        assetName,
                        (string name, Texture2D o) =>
                    {
                        loadedAssets[loaded] = o;
                        loaded++;
                    },
                        (name, error, reason, autoyaStatus) =>
                    {
                        Fail("failed to load asset:" + name + " reason:" + reason);
                    }
                        );
                }
                else if (assetName.EndsWith(".txt"))
                {
                    Autoya.AssetBundle_LoadAsset(
                        assetName,
                        (string name, TextAsset o) =>
                    {
                        loadedAssets[loaded] = o;
                        loaded++;
                    },
                        (name, error, reason, autoyaStatus) =>
                    {
                        Fail("failed to load asset:" + name + " reason:" + reason);
                    }
                        );
                }
                else
                {
                    Autoya.AssetBundle_LoadAsset(
                        assetName,
                        (string name, GameObject o) =>
                    {
                        loadedAssets[loaded] = o;
                        loaded++;
                    },
                        (name, error, reason, autoyaStatus) =>
                    {
                        Fail("failed to load asset:" + name + " reason:" + reason);
                    }
                        );
                }
            }
        }

        yield return(WaitUntil(
                         () => allAssetCount == loaded,
                         () => { throw new TimeoutException("failed to load asset in time."); },
                         10
                         ));

        onLoaded(loadedAssets);
    }
Ejemplo n.º 7
0
    public IEnumerator AssetBundle_CachedBundleNamesWillBeUpdated()
    {
        var listDownloaded = false;

        Autoya.AssetBundle_DownloadAssetBundleListsIfNeed(
            status =>
        {
            listDownloaded = true;
        },
            (error, reason, status) =>
        {
        }
            );
        yield return(WaitUntil(
                         () => listDownloaded,
                         () => { throw new TimeoutException("failed to download list."); }
                         ));

        // load 1 asset.
        var done      = false;
        var assetName = string.Empty;

        Autoya.AssetBundle_DownloadAssetBundleListsIfNeed(
            status =>
        {
            assetName = Autoya.AssetBundle_AssetBundleLists().Where(list => list.identity == "main_assets").FirstOrDefault().assetBundles[0].assetNames[0];
            Autoya.AssetBundle_LoadAsset <GameObject>(
                assetName,
                (name, asset) =>
            {
                // succeeded to download AssetBundle and got asset from AB.
                done = true;
            },
                (name, error, reason, autoyaStatus) =>
            {
            }
                );
        },
            (code, reason, asutoyaStatus) =>
        {
            Fail("UpdateListWithOnMemoryAssets failed, code:" + code + " reason:" + reason);
        }
            );

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

        var done2 = false;

        Autoya.AssetBundle_CachedBundleNames(
            names =>
        {
            True(names.Any());
            done2 = true;
        },
            (error, reason) =>
        {
        }
            );

        yield return(WaitUntil(
                         () => done2,
                         () => { throw new TimeoutException("failed to get cached bundle names in time."); }
                         ));
    }