Exemple #1
0
    public IEnumerator PreloadAssetBundles()
    {
        yield return(GetAssetBundleList());

        var done = false;

        Autoya.AssetBundle_Preload(
            "sample.preloadList2.json",
            (willLoadBundleNames, proceed, cancel) =>
        {
            proceed();
        },
            progress =>
        {
        },
            () =>
        {
            done = true;
        },
            (code, reason, autoyaStatus) =>
        {
            Fail("should not be failed. code:" + code + " reason:" + reason);
        },
            (failedAssetBundleName, code, reason, autoyaStatus) =>
        {
        },
            2
            );

        yield return(WaitUntil(
                         () => done,
                         () => { throw new TimeoutException("not yet done."); }
                         ));
    }
Exemple #2
0
    public IEnumerator PreloadAssetBundleBeforeGetAssetBundleListWillFail()
    {
        True(!Autoya.AssetBundle_IsAssetBundleFeatureReady(), "not match.");

        var done = false;

        Autoya.AssetBundle_Preload(
            "1.0.0/sample.preloadList.json",
            (willLoadBundleNames, proceed, cancel) =>
        {
            proceed();
        },
            progress =>
        {
        },
            () =>
        {
            Fail("should not be succeeded.");
        },
            (code, reason, autoyaStatus) =>
        {
            True(code == -(int)Autoya.AssetBundlesError.NeedToDownloadAssetBundleList, "not match. code:" + code + " reason:" + reason);
            done = true;
        },
            (failedAssetBundleName, code, reason, autoyaStatus) =>
        {
        },
            1
            );

        yield return(WaitUntil(
                         () => done,
                         () => { throw new TimeoutException("not yet done."); }
                         ));
    }
    // 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 #4
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.
            );
    }