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 GetAssetBundleBeforeGetAssetBundleListBecomeFailed()
    {
        var loaderTest = new AssetBundleLoaderTests();
        var cor        = loaderTest.LoadListFromWeb();

        yield return(cor);

        var list = cor.Current as AssetBundleList;

        var done      = false;
        var assetName = list.assetBundles[0].assetNames[0];

        Autoya.AssetBundle_LoadAsset <GameObject>(
            assetName,
            (name, obj) =>
        {
            Fail("should not comes here.");
        },
            (name, err, reason, autoyaStatus) =>
        {
            True(err == AssetBundleLoadError.AssetBundleListIsNotReady, "not match.");
            done = true;
        }
            );

        yield return(WaitUntil(
                         () => done,
                         () => { throw new TimeoutException("not yet failed."); }
                         ));
    }
Exemple #3
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 #5
0
    public IEnumerator GetAssetBundle()
    {
        yield return(GetAssetBundleList());

        var lists = Autoya.AssetBundle_AssetBundleLists();

        True(lists != null);

        var done      = false;
        var assetName = lists.Where(list => list.identity == "main_assets").FirstOrDefault().assetBundles[0].assetNames[0];

        if (assetName.EndsWith(".png"))
        {
            Autoya.AssetBundle_LoadAsset <Texture2D>(
                assetName,
                (name, tex) =>
            {
                done = true;
            },
                (name, err, reason, autoyaStatus) =>
            {
                Fail("name:" + name + " err:" + err + " reason:" + reason);
            }
                );
        }
        else
        {
            Autoya.AssetBundle_LoadAsset <GameObject>(
                assetName,
                (name, obj) =>
            {
                done = true;
            },
                (name, err, reason, autoyaStatus) =>
            {
                Fail("name:" + name + " err:" + err + " reason:" + reason);
            }
                );
        }


        yield return(WaitUntil(
                         () => done,
                         () => { throw new TimeoutException("not yet done."); }
                         ));

        Autoya.AssetBundle_UnloadOnMemoryAssetBundles();
    }
Exemple #6
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 #7
0
    public IEnumerator DownloadedMultipleListsAreEnabled()
    {
        yield return(DownloadMultipleBundleListAtOnce());

        // それぞれのリストの要素を使って、動作していることを確認する。

        var mainAssetsAssetName = Autoya.AssetBundle_AssetBundleLists().Where(list => list.identity == "main_assets").FirstOrDefault().assetBundles[0].assetNames[0];
        var subAssetsAssetName  = Autoya.AssetBundle_AssetBundleLists().Where(list => list.identity == "sub_assets").FirstOrDefault().assetBundles[0].assetNames[0];


        GameObject mainAsset = null;

        Autoya.AssetBundle_LoadAsset <GameObject>(
            mainAssetsAssetName,
            (name, asset) =>
        {
            mainAsset = asset;
        },
            (name, error, reason, status) =>
        {
        }
            );

        TextAsset subAsset = null;

        Autoya.AssetBundle_LoadAsset <TextAsset>(
            subAssetsAssetName,
            (name, asset) =>
        {
            subAsset = asset;
        },
            (name, error, reason, status) =>
        {
        }
            );

        yield return(WaitUntil(
                         () => mainAsset != null && subAsset != null,
                         () => { throw new TimeoutException("failed to load."); }
                         ));
    }
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.
            );
    }
    // 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 #11
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);
    }
Exemple #12
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."); }
                         ));
    }