示例#1
0
    private void OnDownloadAR_scene(AsyncOperationHandle <IList <IResourceLocation> > obj)
    {
        AR_scene = new List <IResourceLocation>(obj.Result);

        Debug.Log(AR_scene[0]);

        downloadSize = Addressables.GetDownloadSizeAsync(AR_scene[0]);
        Debug.Log(downloadSize.Result);
        DownloadScene_Size1.text = downloadSize.Result.ToString();
        DownloadScene_Size2.text = downloadSize.Result.ToString();


        if (downloadSize.Result > 0)
        {
            // Delete old Bundle hahaha
            //Caching.ClearCache();

            Caching.ClearAllCachedVersions("remote_arscene_scenes_all");

            StartCoroutine(LoadRoutine());
        }
        else
        {
            Debug.Log("There is no Update");
            Addressables.LoadSceneAsync(AR_scene[0]);
        }
    }
示例#2
0
        /// <summary>
        /// Delete all cached asset bundle.
        /// </summary>
        static public void ClearCachedAssetBundleAll()
        {
            Debug.LogFormat("{0}アセットバンドルキャッシュをすべて削除", kLog);

#if UNITY_2017_1_OR_NEWER
            Caching.ClearCache();
#else
            Caching.CleanCache();
#endif

            if (!manifest)
            {
                return;
            }

            foreach (var bundleName in manifest.GetAllAssetBundles())
            {
                var hash = manifest.GetAssetBundleHash(bundleName);
                UnloadAssetBundleInternal(bundleName);
                if (Caching.IsVersionCached(bundleName, hash))
                {
                    Debug.LogFormat("{0}キャッシュ削除 : {1}({2})", kLog, bundleName, hash.ToString().Substring(0, 4));
#if UNITY_2017_1_OR_NEWER
                    Caching.ClearAllCachedVersions(bundleName);
#else
                    var request = UnityWebRequest.GetAssetBundle(bundleName, hash, uint.MaxValue);
                    request.Send();
                    request.Abort();
#endif
                }
            }
        }
 void RemoveCacheEntries()
 {
     foreach (string cacheDir in m_CacheDirsForRemoval)
     {
         string bundlename = Path.GetFileName(cacheDir);
         Caching.ClearAllCachedVersions(bundlename);
         Directory.Delete(cacheDir); // Caching.ClearAllCachedVersions leaves empty directories
     }
     CompleteInternal(true, true, null);
 }
    public static int ClearAllCachedVersions_s(IntPtr l)
    {
        int result;

        try
        {
            string assetBundleName;
            LuaObject.checkType(l, 1, out assetBundleName);
            bool b = Caching.ClearAllCachedVersions(assetBundleName);
            LuaObject.pushValue(l, true);
            LuaObject.pushValue(l, b);
            result = 2;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
    private IEnumerator GetLoginAssetBundle(string uri, Hash128 hash, string bundleName)
    {
        while (!Caching.ready)
        {
            yield return(null);
        }

        if (!Caching.IsVersionCached("http://127.0.0.1:8888/loginbutton", hash))
        {
            Debug.Log(Caching.IsVersionCached("http://127.0.0.1:8888/loginbutton", hash));
            Caching.ClearAllCachedVersions(bundleName);
        }

        UnityWebRequest bundleWebRequest = UnityWebRequestAssetBundle.GetAssetBundle(uri, hash);

        yield return(bundleWebRequest.SendWebRequest());

        if (bundleWebRequest.isHttpError)
        {
            yield break;
        }
        else
        {
            AssetBundle loginBundle = DownloadHandlerAssetBundle.GetContent(bundleWebRequest);

            if (loginBundle == null)
            {
                Debug.Log("Failed to load AssetBundle!");
                yield break;
            }
            GameObject prefab = loginBundle.LoadAsset <GameObject>("Login");
            GameObject login  = Instantiate(prefab);
            login.transform.SetParent(parents.transform);
            login.transform.localPosition = new Vector2(-400, 0);
            icon.GetComponent <UnityEngine.UI.Image>().sprite = login.GetComponentsInChildren <UnityEngine.UI.Image>()[0].sprite;

            bundleWebRequest.Dispose();
        }
    }
    // サーバからアセットバンドルをダウンロードする
    private static IEnumerator Download(string[] assetBundleNames, OnDownloadProgressUpdate update)
    {
        // キャッシュできる状態か確認
        while (!Caching.ready)
        {
            yield return(null);
        }

        // アセットバンドルを全てダウンロードするまで回す
        fileIndex = 0;
        do
        {
            // baseURLにAssetBuddle名を付与してURL生成
            string bundleName  = assetBundleNames[fileIndex];
            string url         = baseURL + bundleName;
            string manifestURL = url + ".manifest";
            // URLキャッシュ防止のためタイムスタンプを付与
            url         += ((url.Contains("?")) ? "&" : "?") + "t=" + DateTime.Now.ToString("yyyyMMddHHmmss");
            manifestURL += ((manifestURL.Contains("?")) ? "&" : "?") + "t=" + DateTime.Now.ToString("yyyyMMddHHmmss");

            // CRCチェックを行うか確認
            // manifestファイルをDL
            UnityWebRequest wwwManifest = UnityWebRequest.Get(manifestURL);
            // ダウンロードを待つ
            yield return(wwwManifest.SendWebRequest());

            // manifestが存在していた場合はCRCチェックをする
            uint latestCRC = 0;
            if (string.IsNullOrEmpty(wwwManifest.error))
            {
                // manifest内部のCRCコードを抽出する
                string[] lines = wwwManifest.downloadHandler.text.Split(new string[] { "CRC: " }, StringSplitOptions.None);
                latestCRC = uint.Parse(lines[1].Split(new string[] { "\n" }, StringSplitOptions.None)[0]);

#if UNITY_2017_1_OR_NEWER
                // キャッシュを個別削除する
                string key = "km_assetbundleversioncache_" + bundleName;
                if (PlayerPrefs.HasKey(key))
                {
                    string currentCRC = PlayerPrefs.GetString(key);
                    if (currentCRC != latestCRC.ToString())
                    {
                        PlayerPrefs.SetString(key, latestCRC.ToString()); // 新しいcrcを保存
                        Caching.ClearAllCachedVersions(bundleName);       // 既存のキャッシュを削除
                    }
                    Debug.Log("[" + bundleName + ".manifest] \n" + "Latest CRC : " + latestCRC + "  Current CRC: " + currentCRC);
                }
                else
                {
                    PlayerPrefs.SetString(key, latestCRC.ToString()); // 新しいcrcを保存
                }
                latestCRC = 0;
#endif
            }
            else
            {
                Debug.Log(bundleName + ".manifest has not found.");
            }

            // CRCチェックしてダウンロード開始
            using (UnityWebRequest www = UnityWebRequest.GetAssetBundle(url, ver, latestCRC))
            {
                // ダウンロード開始
                www.SendWebRequest();
                // ダウンロードが完了するまでプログレスを更新する
                while (www.downloadProgress < 1f)
                {
                    // progress設定
                    float progress = 0f;
                    if (www.downloadProgress > 0)
                    {
                        progress = www.downloadProgress;
                    }
                    // 更新する
                    update(progress, fileIndex, false, www.error);
                    yield return(new WaitForEndOfFrame());
                }

                // エラー処理
                if (!string.IsNullOrEmpty(www.error))
                {
                    // 完了通知
                    update(0f, fileIndex, false, www.error);
                    string err = www.error;
                    Debug.Log(www.error);
                    // wwwを解放する
                    www.Dispose();
                    throw new Exception("WWW download had an error:" + err);
                }
                // ロードしたアセットバンドルをセット
                AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);

                // AssetBundle内部に同名のCRYPTO_SIGNがあった場合、暗号化Assetと判断して復号する
                if (bundle.Contains(CRYPTO_SIGN + bundle.name))
                {
                    bundle = DecryptingAssetBundle(bundle);
                    yield return(bundle);
                }
                bundleDic.Add(bundleName, bundle);
                // wwwを解放する
                www.Dispose();
            }
        } while (++fileIndex < assetBundleNames.Length);

        // 完了通知
        update(1f, fileIndex, true, null);
    }
示例#7
0
    void LoadTable(Uri uri, string assetBundleName, Hash128 hash, uint crc = 0)
    {
        Debug.Log(Caching.ready);

        //構造体生成
        var cachedAssetBundle = new CachedAssetBundle(assetBundleName, hash);


        //全てのtableのキャッシュ削除
        Caching.ClearAllCachedVersions(assetBundleName);


        //if (Caching.IsVersionCached(cachedAssetBundle))
        //{
        //    Debug.Log("キャッシュから");
        //    //キャッシュ存在
        //    string dataPath = AssetBundlePath(cachedAssetBundle);

        //    Debug.Log(dataPath);


        //    var op = UnityEngine.AssetBundle.LoadFromFileAsync(dataPath);
        //    op.completed += (obj) =>
        //    {
        //        // ダウンロード成功
        //        Debug.Log("ダウンロード成功");

        //        AssetBundle bundle = op.assetBundle;

        //        var prefab = bundle.LoadAllAssets();

        //        string text = prefab[0].ToString();

        //        table = JsonUtility.FromJson<AssetBundleTable>(text);

        //        Debug.Log("バージョン" + table.Version);

        //        int preVersion = PlayerPrefs.GetInt("DOWNLOAD", -1);

        //        if (preVersion != table.Version)
        //        {
        //            Debug.Log("新しいバージョンがあります");
        //        }

        //        LoadEnd(LOAD.TABLE);

        //    };
        //}
        //else
        //{
        Debug.Log("サーバーから");

        var request = UnityWebRequestAssetBundle.GetAssetBundle(uri, cachedAssetBundle, crc);

        var op = request.SendWebRequest();

        op.completed += (obj) =>
        {
            if (op.webRequest.isHttpError || op.webRequest.isNetworkError)
            {
                Debug.Log($"ダウンロードに失敗しました!! error:{op.webRequest.error}");
                LoadFailed();
            }
            else
            {
                // ダウンロード成功
                Debug.Log("ダウンロード成功");

                var bundle = DownloadHandlerAssetBundle.GetContent(request);

                var prefab = bundle.LoadAllAssets();

                string text = prefab[0].ToString();

                table = JsonUtility.FromJson <AssetBundleTable>(text);

                Debug.Log("バージョン" + table.Version);

                int preVersion = PlayerPrefs.GetInt("VERSION", -1);

                if (preVersion != table.Version)
                {
                    Debug.Log("新しいバージョンがあります");

                    newDataObj.SetActive(true);
                }
                else
                {
                    Debug.Log("同じバージョン");

                    downLoadObj.SetActive(true);
                    LoadEnd(LOAD.TABLE);
                }
            }
        };

        //}
    }
示例#8
0
    // [MenuItem("Test/testIfBundleAndcaching")]
    // public static void TestBundleCaching()
    // {
    //     //
    //     var instance = FindObjectOfType<test>();
    //     instance.instanceOfBundles.IsBundleCached("lvl4");
    // }
    // [MenuItem("Test/testClearbundleFromStreamingAndcaching")]
    public static void TestBundleCachingClear()
    {
        bool cleared = Caching.ClearAllCachedVersions("lvl4".ToLower());

        Debug.Log(" Was it cleared? : " + cleared);
    }
示例#9
0
        /// <summary>
        /// Update manifest.
        /// Compare manifests and delete old cached bundles.
        /// Starts download of manifest asset bundle.
        /// Returns the manifest asset bundle downolad operation object.
        /// </summary>
        /// <param name="newManifest">Asset bundle manifest.</param>
        static void SetManifest(AssetBundleManifest newManifest)
        {
            if (!newManifest)
            {
                Debug.LogErrorFormat("{0}マニフェスト更新 失敗 : {1}", kLog, patch);
                return;
            }

            var oldManifest = AssetManager.manifest;

            AssetManager.manifest = newManifest;

            if (oldManifest)
            {
                var oldBundles = new HashSet <string>(oldManifest.GetAllAssetBundles());
                var newBundles = new HashSet <string>(newManifest.GetAllAssetBundles());

                // 新規
                var sb    = new StringBuilder();
                var array = newBundles.Except(oldBundles).ToArray();
                sb.AppendFormat("[Added] {0}\n", array.Length);
                foreach (var bundleName in array)
                {
                    sb.AppendFormat("  > {0} ({1})\n", bundleName, newManifest.GetAssetBundleHash(bundleName).ToString().Substring(0, 4));
                }

                // 削除
                array = oldBundles.Except(newBundles).ToArray();
                sb.AppendFormat("\n[Deleted : キャッシュは削除されます] {0}\n", array.Length);
                foreach (var bundleName in array)
                {
                    sb.AppendFormat("  > {0} ({1})\n", bundleName, oldManifest.GetAssetBundleHash(bundleName).ToString().Substring(0, 4));
                }


                // 更新
                array = oldBundles
                        .Intersect(newBundles)
                        .Select(name => new { name = name, oldHash = oldManifest.GetAssetBundleHash(name), newHash = newManifest.GetAssetBundleHash(name), })
                        .Where(x => x.oldHash != x.newHash)
                        .Select(x => string.Format("{0} ({1} -> {2})", x.name, x.oldHash.ToString().Substring(0, 4), x.newHash.ToString().Substring(0, 4)))
                        .ToArray();
                sb.AppendFormat("\n[Updated : 古いキャッシュは削除されます] {0}\n", array.Length);
                foreach (var bundleName in array)
                {
                    sb.AppendLine("  > " + bundleName);
                }

#if UNITY_2017_1_OR_NEWER
                // 削除
                foreach (var name in oldBundles.Except(newBundles))
                {
                    UnloadAssetBundleInternal(name);
                    Caching.ClearAllCachedVersions(name);
                    Debug.LogFormat("{0}キャッシュ削除 : {1}", kLog, name);
                }

                // 更新
                foreach (var name in newBundles)
                {
                    UnloadAssetBundleInternal(name);
                    Caching.ClearOtherCachedVersions(name, newManifest.GetAssetBundleHash(name));
                    Debug.LogFormat("{0}キャッシュ削除 : {1}", kLog, name);
                }
#else
                foreach (var name in oldBundles.Where(newBundles.Contains))
                {
                    var oldHash = oldManifest.GetAssetBundleHash(name);
                    var newHash = newManifest.GetAssetBundleHash(name);

                    // The bundle has removed or changed. Need to delete cached bundle.
                    if (oldHash != newHash)
                    {
                        UnloadAssetBundleInternal(name);
                        if (Caching.IsVersionCached(name, oldHash))
                        {
                            Debug.LogFormat("{0}キャッシュ削除 : {1}({2})", kLog, name, oldHash.ToString().Substring(0, 4));
                            var request = UnityWebRequest.GetAssetBundle(name, oldHash, uint.MaxValue);
                            request.Send();
                            request.Abort();
                        }
                    }
                }
#endif
                Debug.LogFormat("{0}マニフェスト更新 完了 : {2}\n変更は以下の通りです:\n{1}", kLog, sb, patch);
            }
            else
            {
                var newBundles = newManifest.GetAllAssetBundles();

                // 新規
                var sb = new StringBuilder();
                sb.AppendFormat("[Added] {0}\n", newBundles.Length);
                foreach (var bundleName in newBundles)
                {
                    sb.AppendFormat("  > {0} ({1})\n", bundleName, newManifest.GetAssetBundleHash(bundleName).ToString().Substring(0, 4));
                }
                Debug.LogFormat("{0}マニフェスト更新 完了 : {2}\n変更は以下の通りです:\n{1}", kLog, sb, patch);
            }
            instance.storedPatch = patch;
        }