IEnumerator InstanciatePrefab(string prefabName, Vector3 position)
    {
        Autoya.AssetBundle_DownloadAssetBundleListsIfNeed(status => { }, (code, reason, autoyaStatus) => { });

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

        Autoya.AssetBundle_LoadAsset <GameObject>(
            prefabName,
            (assetName, prefab) =>
        {
            Debug.Log("asset:" + assetName + " is successfully loaded as:" + prefab);

            // instantiate asset.
            Instantiate(prefab, position, Quaternion.identity);
        },
            (assetName, err, reason, status) =>
        {
            Debug.LogError("failed to load assetName:" + assetName + " err:" + err + " reason:" + reason);
        }
            );
    }
Exemple #2
0
    public IEnumerator AssetBundle_NotCachedBundleNamesInSomeAssetCached()
    {
        // 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."); }
                         ));

        // 1 or more assets are cached.(by dependencies.)


        string[] names = null;
        Autoya.AssetBundle_NotCachedBundleNames(
            bundleNames =>
        {
            names = bundleNames;
        },
            (error, reason) =>
        {
            Debug.Log("error:" + error + " reason:" + reason);
        }
            );

        yield return(WaitUntil(
                         () => names != null && 0 < names.Length,
                         () => { throw new TimeoutException("failed to get Not chached bundle names."); }
                         ));

        // 1 or more assets are cached.(by dependencies.)
        var wholeAssetBundleNames = Autoya.AssetBundle_AssetBundleLists().SelectMany(list => list.assetBundles).Select(bundleInfo => bundleInfo.bundleName).ToArray();

        True(names.Length < wholeAssetBundleNames.Length);
        True(!names.Contains(assetName), "cotntains.");
    }
    IEnumerator Start()
    {
        // need to wait finish authentication.
        while (!Autoya.Auth_IsAuthenticated())
        {
            yield return(null);
        }

        /*
         *              Autoya manages whole assetBundle information as the "AssetBundleList".
         *              latest file is located at url that is generated by
         *                      OverridePoints.OnAssetBundleListDownloadUrlRequired method.
         *
         */
        Autoya.AssetBundle_DownloadAssetBundleListsIfNeed(
            (status) =>
        {
            Debug.Log("assetBundleList download succeeded. status:" + status);

            /*
             *                      then, you can load asset from web.
             *
             *                      assetBundleList has the information which asset is contained by specific assetBundle.
             *                              (asset <-containes-- assetBundle <-info contains-- assetBundleList)
             *
             *                      the downloaded assetBundleList is stored in device. you can set the location and the way of read/write the list via OverridePoints.cs.
             */

            /*
             *                      load asset from web or cache.
             *                      automatically download bundle then load asset on memory.
             */
            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, autoyaStatus) =>
            {
                Debug.LogError("failed to load assetName:" + assetName + " err:" + err + " reason:" + reason + " autoyaStatus:" + autoyaStatus);
            }
                );
        },
            (code, reason, autoyaStatus) =>
        {
            Debug.LogError("failed to download assetBundleList from OverridePoints.AssetBundleListDownloadUrl() supplied url. code:" + code + " reason:" + reason);
        }
            );
    }
Exemple #4
0
    void Start()
    {
        /*
         *              Autoya manages whole assetBundle information as the "AssetBundleList".
         *              latest file is located at
         *                      AssetBundlesSettings.ASSETBUNDLES_URL_DOWNLOAD_ASSETBUNDLELIST
         *
         */
        Autoya.AssetBundle_DownloadAssetBundleListsIfNeed(
            (status) =>
        {
            Debug.Log("assetBundleList download succeeded. status:" + status);

            /*
             *                      then, you can load asset from web.
             *
             *                      assetBundleList has the information which asset is contained by specific assetBundle.
             *                              (asset <-containes-- assetBundle <-info contains-- assetBundleList)
             *
             *                      the downloaded assetBundleList is stored in device. you can set the location and the way of read/write the list via OverridePoints.cs.
             */

            /*
             *                      load asset from web or cache.
             *                      automatically download bundle then load asset on memory.
             */
            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, autoyaStatus) =>
            {
                Debug.LogError("failed to load assetName:" + assetName + " err:" + err + " reason:" + reason + " autoyaStatus:" + autoyaStatus);
            }
                );
        },
            (code, reason, autoyaStatus) =>
        {
            Debug.LogError("failed to download assetBundleList from OverridePoints.AssetBundleListDownloadUrl() supplied url. code:" + code + " reason:" + reason);
        }
            );
    }
Exemple #5
0
    public IEnumerator GetAssetBundleList()
    {
        var done = false;

        Autoya.AssetBundle_DownloadAssetBundleListsIfNeed(
            status =>
        {
            done = true;
        },
            (code, reason, asutoyaStatus) =>
        {
            Debug.Log("GetAssetBundleList failed, code:" + code + " reason:" + reason);
            // do nothing.
        }
            );

        yield return(WaitUntil(
                         () => done,
                         () => { throw new TimeoutException("faild to get assetBundleList."); }
                         ));
    }
Exemple #6
0
    public IEnumerator AssetBundle_NotCachedBundleNames()
    {
        var listDownloaded = false;

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

        string[] names = null;
        Autoya.AssetBundle_NotCachedBundleNames(
            bundleNames =>
        {
            names = bundleNames;
        },
            (error, reason) =>
        {
            Debug.Log("error:" + error + " reason:" + reason);
        }
            );

        yield return(WaitUntil(
                         () => names != null && 0 < names.Length,
                         () => { throw new TimeoutException("failed to get Not chached bundle names."); }
                         ));

        // no asset cached.
        var wholeAssetBundleNames = Autoya.AssetBundle_AssetBundleLists().SelectMany(list => list.assetBundles).Select(bundleInfo => bundleInfo.bundleName).ToArray();

        True(names.Length == wholeAssetBundleNames.Length);
    }
Exemple #7
0
    public IEnumerator AssetBundle_CachedBundleNames()
    {
        var listDownloaded = false;

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

        var done = false;

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

        yield return(WaitUntil(
                         () => done,
                         () => { throw new TimeoutException("failed to get cached bundle names in time."); }
                         ));
    }
Exemple #8
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.
            );
    }
    // 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.
            );
    }
Exemple #10
0
    public IEnumerator StoredAssetBundleListIsEnoughOnBoot()
    {
        // 事前に保存済みのデータを消す、これでほかのテストの影響を受けない初期化されたデータだけができる。
        Autoya.Persist_DeleteByDomain(AppSettings.APP_STORED_RUNTIME_MANIFEST_DOMAIN);
        Autoya.Persist_DeleteByDomain(AssetBundlesSettings.ASSETBUNDLES_LIST_STORED_DOMAIN);

        var dataPath = Application.persistentDataPath;

        Autoya.TestEntryPoint(dataPath);
        {
            var loginDone = false;
            Autoya.Auth_SetOnAuthenticated(
                () =>
            {
                loginDone = true;
            }
                );

            yield return(WaitUntil(
                             () =>
            {
                return loginDone;
            },
                             () => { throw new TimeoutException("timeout."); }
                             ));
        }

        var abReady = false;

        Autoya.AssetBundle_DownloadAssetBundleListsIfNeed(
            results =>
        {
            abReady = true;
        },
            (code, reason, status) =>
        {
            Debug.LogError("failed to download ABList, code:" + code + " reason:" + reason);
        }
            );
        while (!abReady)
        {
            yield return(null);
        }

        // reboot autoya.
        Autoya.TestEntryPoint(dataPath);

        {
            var loginDone = false;
            Autoya.Auth_SetOnAuthenticated(
                () =>
            {
                loginDone = true;
            }
                );

            yield return(WaitUntil(
                             () =>
            {
                return loginDone;
            },
                             () => { throw new TimeoutException("timeout."); }
                             ));
        }

        Assert.True(Autoya.AssetBundle_IsAssetBundleFeatureReady(), "not ready.");
    }
Exemple #11
0
    public IEnumerator RemoveUnnecessaryStoredAssetBundleListOnBoot()
    {
        // 事前に保存済みのデータを消す、これでほかのテストの影響を受けない初期化されたデータだけができる。
        Autoya.Persist_DeleteByDomain(AppSettings.APP_STORED_RUNTIME_MANIFEST_DOMAIN);
        Autoya.Persist_DeleteByDomain(AssetBundlesSettings.ASSETBUNDLES_LIST_STORED_DOMAIN);

        var dataPath = Application.persistentDataPath;

        Autoya.TestEntryPoint(dataPath);
        {
            var loginDone = false;
            Autoya.Auth_SetOnAuthenticated(
                () =>
            {
                loginDone = true;
            }
                );

            yield return(WaitUntil(
                             () =>
            {
                return loginDone;
            },
                             () => { throw new TimeoutException("timeout."); }
                             ));
        }
        var abReady = false;

        Autoya.AssetBundle_DownloadAssetBundleListsIfNeed(
            results =>
        {
            abReady = true;
        },
            (code, reason, status) =>
        {
            Debug.LogError("failed to download ABList, code:" + code + " reason:" + reason);
        }
            );
        while (!abReady)
        {
            yield return(null);
        }

        var defaultGeneratedABListIdentities = Autoya.AssetBundle_AssetBundleLists().Select(list => list.identity).ToArray();

        // このあとまたAutoyaを起動するので、ABListがあるdomainに存在するファイルに、独自の「アプリのアプデでいらなくなった」という状態のリストを追加する。
        var dummyListIdentity = "dummy_reomved";
        var removedABListStr  = "{\"identity\":\"" + dummyListIdentity + "\",\"target\":\"iOS\",\"version\":\"1.0.0\",\"assetBundles\":[{\"bundleName\":\"sample\",\"assetNames\":[\"Assets/AutoyaTests/RuntimeData/AssetBundles/SubResources/sample.txt\"],\"dependsBundleNames\":[],\"crc\":1672014196,\"hash\":\"720461ec2bb1aecd2ce41903f3a7d205\",\"size\":754}]}";

        Autoya.Persist_Update(AssetBundlesSettings.ASSETBUNDLES_LIST_STORED_DOMAIN, "dummyList.json", removedABListStr);

        Autoya.TestEntryPoint(dataPath);

        {
            var loginDone = false;
            Autoya.Auth_SetOnAuthenticated(
                () =>
            {
                loginDone = true;
            }
                );

            yield return(WaitUntil(
                             () =>
            {
                return loginDone;
            },
                             () => { throw new TimeoutException("timeout."); }
                             ));
        }

        abReady = false;

        Autoya.AssetBundle_DownloadAssetBundleListsIfNeed(
            results =>
        {
            abReady = true;
        },
            (code, reason, status) =>
        {
            Debug.LogError("failed to download ABList, code:" + code + " reason:" + reason);
        }
            );

        while (!abReady)
        {
            yield return(null);
        }

        // dummy abList should be deleted.
        var lists            = Autoya.AssetBundle_AssetBundleLists();
        var storedIdentities = lists.Select(list => list.identity).ToArray();

        Assert.True(!storedIdentities.Contains(dummyListIdentity), "contained.");

        // all identites are matched.
        foreach (var defaultGeneratedABListIdentitiy in defaultGeneratedABListIdentities)
        {
            Assert.True(storedIdentities.Contains(defaultGeneratedABListIdentitiy), "not contained.");
        }

        foreach (var storedIdentity in storedIdentities)
        {
            Assert.True(defaultGeneratedABListIdentities.Contains(storedIdentity), "not contained.");
        }
    }
    // 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.
         *
         *              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);
        }

        /*
         *              get preloadList from web.
         *              the base filePath settings is located at AssetBundlesSettings.ASSETBUNDLES_URL_DOWNLOAD_PRELOADLIST.
         *
         *              this preloadList contains 1 assetBundleName, "bundlename", contains 1 asset, "textureName.png"
         *
         *              note that:
         *                      this feature requires the condition:"assetBundleList is stored." for getting assetBundleInfo. (crc, hash, and dependencies.)
         */

        var preloadListPath = "sample.preloadList.json";

        // this will become ASSETBUNDLES_URL_DOWNLOAD_PRELOADLIST + sample.preloadList.json.


        // download preloadList from web then preload described assetBundles.
        Autoya.AssetBundle_Preload(
            preloadListPath,
            (willLoadBundleNames, proceed, cancel) =>
        {
            var totalWeight = Autoya.AssetBundle_GetAssetBundlesWeight(willLoadBundleNames);
            Debug.Log("start downloading bundles. total weight:" + totalWeight);

            proceed();
        },
            progress =>
        {
            Debug.Log("progress:" + progress);
        },
            () =>
        {
            Debug.Log("preloading 1 listed assetBundles is finished.");

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

                // create gameObject, then set tex to it as sprite.
                var gameObj           = new GameObject("createdGameObject");
                var imageComponent    = gameObj.AddComponent <Image>();
                imageComponent.sprite = Sprite.Create(image, new Rect(0.0f, 0.0f, image.width, image.height), new Vector2(0.5f, 0.5f), 100.0f);

                // find uGUI canvas then set.
                var canvas = GameObject.Find("Canvas");
                gameObj.transform.SetParent(canvas.transform, false);
            },
                (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.
            );
    }
Exemple #13
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."); }
                         ));
    }
Exemple #14
0
    IEnumerator DownloadBySpecificJsonListNameCoroutine(string jsonListName)
    {
        Autoya.AssetBundle_DownloadAssetBundleListsIfNeed(status => { }, (code, reason, autoyaStatus) => { });

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


        //使わないけど、インターネット上のフルパスは何か、を表示しておく
        var fullPathForJsonListURL = AutoyaFramework.Settings.AssetBundles.AssetBundlesSettings.ASSETBUNDLES_URL_DOWNLOAD_PRELOADLIST + jsonListName;

        Debug.Log("このURLのjsonに書いてある未キャッシュのアセットバンドルを全部ダウンロードします" + fullPathForJsonListURL);

        //memo:
        //この処理で気を付ける点として、fullPathForJsonListURLのURLを直接ブラウザで見てみると、アセットバンドルの「名前だけ」がjsonのリストに含まれています
        //では個別URLとか、CRCとか、バージョン情報とかは無いのに、なんで名前だけでダウンロード出来てしまうのかと言うと
        //Autoyaでは既にアセットバンドルをビルドした時の後処理として、これら個別URL,CRCなどの塊をキャッシュで保持してくれる仕組みがあります。
        //Autoya.AssetBundle_DownloadAssetBundleListsIfNeed(status => { }, (code, reason, autoyaStatus) => { });
        //↑これがその処理です。内部では色々な事をしていますが、あまり意識しなくてもおまじないとして使えるようになっています。
        //ただし、気を付ける点としてAutoyaのレールを外れる(例えばアセットバンドルだけを別プロジェクトで運用する、あるいは自前でバージョン処理を書く、設定ファイルの記載を無視して自前で挙動やURLを指定する)
        //と、一気に考えることが増えます。それはお勧めしません。

        // download preloadList from web then preload described assetBundles.
        Autoya.AssetBundle_Preload(
            jsonListName,
            (willLoadBundleNames, proceed, cancel) =>
        {
            //ここで、(ダウンロード予定のリストは取得した後、アセットバンドルのダウンロードを始める直前の処理を差し込めます
            //ユースケースとしては「〇〇バイトのダウンロードを行います。よろしいですか?」みたいな感じです。
            var totalWeight = Autoya.AssetBundle_GetAssetBundlesWeight(willLoadBundleNames);

            //もし、ダウンロード済だったらダイアログを出さずにさっさとこの関数を抜けたい。という場合は以下のように書いてください

            /*
             * if (totalWeight < 1)
             * {
             *  proceed();
             * }
             */
            Debug.Log(jsonListName + ":------will loading---------" + totalWeight + " byte");
            foreach (var item in willLoadBundleNames)
            {
                Debug.Log(item);
            }
            //ダイアログを出して、ダウンロードして良いか聞く。これは便利…
            Dialog.Show(new UnityEngine.Events.UnityAction(proceed), new UnityEngine.Events.UnityAction(cancel), totalWeight + "バイトのダウンロードを行います。良いですか");
            Debug.Log("------end------");
        },
            progress =>
        {
            //アセットバンドルのダウンロードが一個終わる度にここが呼び出され、progressの値が0から1に増えていきます。
            //大変残念ですが、ダウンロードすべきアセットバンドルが1個だけの場合は、このprogressは1だけになります。
            //なぜかというと1個づつアセットバンドルがダウンロード完了した毎に、Autoyaはprogressのイベントを発火するためです。
            //こういう小さなデモアプリだと1しか出なくて不便だ…と思われるかもしれませんが、実際の運用では問題ないです。
            Debug.Log("progress:" + progress);
        },
            () =>
        {
            //ここでダウンロードが全部終わった、あるいは全部キャッシュ済みだった時の処理を書く
            //Instanciateするとか、実際に使うシーンに遷移するとか
            //一応今回はメインで使うシーンに遷移、というパターンのデモアプリにしています。
            Debug.Log("preloading all listed assetBundles is finished.");

            //もし、ダウンロード直後にInstanciateしたい、とかなら、以下のように書きます

            /*
             * 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.
            );
    }
Exemple #15
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
                         ));
    }
Exemple #16
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);
    }
Exemple #17
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);
        }
    }