/// <summary> /// Gets the asset bundle version file. /// </summary> /// <returns>The asset bundle version file.</returns> /// <param name="success">Success.</param> /// <param name="failed">Failed.</param> IEnumerator GetAssetBundleVersionFile(Action <string> success, Action <string, string> failed) { string abVersionFileUrl = AssetBundleSettings.GetAssetBundleServerURL() + "/" + AssetBundleSettings.ASSETBUNDLE_VERSION_FILE_NAME; WWW _www = new WWW(abVersionFileUrl); yield return(_www); if (string.IsNullOrEmpty(_www.error)) { if (AssetBundleSettings.IsEncryptAssetBundle) { byte[] decryptedBytes = EncryptDecryptUtil.DecryptBytesToBytes(_www.bytes, AssetBundleSettings.PASSWORD_ENCRYPT_DECRYPT_ASSETBUNDLE); _assetBundleVersionDB = _objectPacker.Unpack <AssetBundleSettings.AssetBundleTargetDB> (decryptedBytes); } else { _assetBundleVersionDB = _objectPacker.Unpack <AssetBundleSettings.AssetBundleTargetDB> (_www.bytes); } yield return(null); yield return(StartCoroutine(SettingDownloadABList(_www.bytes))); if (success != null) { success(abVersionFileUrl); } } else { if (failed != null) { failed(abVersionFileUrl, _www.error); } } yield return(null); }
/// <summary> /// Settings the download AB list. Get total size needed to be downloaded /// </summary> IEnumerator SettingDownloadABList(byte[] newAssetBundleAssetVersion) { //Load local assetbundle version string path = AssetBundleSettings.localFolderPathSaveAB + "/" + AssetBundleSettings.ASSETBUNDLE_VERSION_FILE_NAME; if (File.Exists(path)) { System.Uri url = new System.Uri(path); WWW _www = new WWW(url.AbsoluteUri); yield return(new WaitUntil(() => { return _www.isDone; })); AssetBundleSettings.AssetBundleTargetDB _oldVersionDB = null; if (AssetBundleSettings.IsEncryptAssetBundle) { byte[] decryptedBytes = EncryptDecryptUtil.DecryptBytesToBytes(_www.bytes, AssetBundleSettings.PASSWORD_ENCRYPT_DECRYPT_ASSETBUNDLE); _oldVersionDB = _objectPacker.Unpack <AssetBundleSettings.AssetBundleTargetDB> (decryptedBytes); } else { _oldVersionDB = _objectPacker.Unpack <AssetBundleSettings.AssetBundleTargetDB> (_www.bytes); } _downloadList = new List <AssetBundleSettings.AssetBundleInfo> (); foreach (var assetBundleInfo in _assetBundleVersionDB.lstAssetBundleInfo) { AssetBundleSettings.AssetBundleInfo oldABInfo = _oldVersionDB.lstAssetBundleInfo.Where(_ => _.assetBundle == assetBundleInfo.assetBundle).FirstOrDefault(); if (oldABInfo == null) { _downloadList.Add(assetBundleInfo); } else { if (assetBundleInfo.version != oldABInfo.version) { _downloadList.Add(assetBundleInfo); } else if (assetBundleInfo.hashAssetBundle != oldABInfo.hashAssetBundle) { _downloadList.Add(assetBundleInfo); } } } } else { _downloadList = new List <AssetBundleSettings.AssetBundleInfo> (_assetBundleVersionDB.lstAssetBundleInfo); } if (!Directory.Exists(AssetBundleSettings.localFolderPathSaveAB)) { Directory.CreateDirectory(AssetBundleSettings.localFolderPathSaveAB); } #if UNITY_IPHONE //No backup to cloud UnityEngine.iOS.Device.SetNoBackupFlag(path); #endif yield return(null); File.WriteAllBytes(path, newAssetBundleAssetVersion); totalSize = 0; foreach (var item in _downloadList) { totalSize += item.size; } yield return(null); }