IEnumerator LoadXml(string xmlpath) { WWW www = new WWW(xmlpath); yield return(www); if (null != www.error) { Debug.Log("加载xmlBundle www error:" + www.error); } string[] names = www.assetBundle.GetAllAssetNames(); for (int i = 0; i < names.Length; i++) { Debug.Log("---[" + i + "]------>" + names[i]); } AssetBundleManifest xml = (AssetBundleManifest)www.assetBundle.LoadAsset("assetbundlemanifest"); //这个名称永远固定,无论bundle名是什么,asset名都是这个 string[] allAssetsBundles = xml.GetAllAssetBundles(); string[] allDepend = xml.GetAllDependencies("assetBundleName"); string[] directDepend = xml.GetDirectDependencies("assetBundleName"); Hash128 hash = xml.GetAssetBundleHash("assetBundleName"); }
/// <summary> /// 获取完总的Manifest后,先加载依赖资源 /// </summary> /// <param name="fileName">需要的资源名称(待扩展名)</param> /// <param name="manifest">总的Manifest</param> /// <returns></returns> public IEnumerator LoadDependenceAsset(string fileName, AssetBundleManifest manifest = null, Action <string, AssetBundleManifest, AssetBundle[]> loadAsset = null) { if (manifest == null) { yield return(null); } string[] dps = manifest.GetAllDependencies(GetLower(fileName)); //先加载依赖资源 Debug.Log("依赖资源的数目:" + dps.Length); AssetBundle[] dpsBundle = new AssetBundle[dps.Length]; for (int i = 0; i < dpsBundle.Length; i++) { Debug.Log(dps[i]); string dUrl = m_assetPath + dps[i]; using (WWW www = WWW.LoadFromCacheOrDownload(dUrl, manifest.GetAssetBundleHash(dps[i]))) //此处通过依赖资源的哈希码作为依赖资源的版本信息来加载 { yield return(www); if (!string.IsNullOrEmpty(www.error)) { Debug.LogError(www.error); } else { dpsBundle[i] = www.assetBundle; } } } if (loadAsset != null) { loadAsset.Invoke(fileName, manifest, dpsBundle); } }
private IEnumerator LoadAssetAsync(string abName, string assetName, Action <UObject> CSFunc) { UObject result; abName = abName.ToLower() + AppConst.ExtName; if (m_LoadedAssetBundles.ContainsKey(abName)) { result = m_LoadedAssetBundles[abName]; } else { var path = AppConst.RelativePath + abName; WWW download = WWW.LoadFromCacheOrDownload(path, m_AssetBundleManifest.GetAssetBundleHash(abName), 0); yield return(download); AssetBundle assetObj = download.assetBundle; m_LoadedAssetBundles.Add(abName, assetObj); result = assetObj.LoadAsset(assetName); } if (CSFunc != null) { CSFunc(result); } }
/// <summary> /// 检测本地文件是否存在已经是否是最新 /// </summary> /// <param name="AssetName"></param> /// <param name="RootAssetsName"></param> /// <param name="localPath"></param> /// <param name="serverAssetManifestfest"></param> /// <param name="CheckCount"></param> /// <returns></returns> bool CheckLocalFileNeedUpdate(string AssetName, Hash128 hash128Server, string RootAssetsName, string localPath, AssetBundleManifest assetBundleManifestLocal) { Hash128 hash128Local; bool isNeedUpdate = false; if (!File.Exists(localPath + "/" + AssetName)) { return(true); //本地不存在,则一定更新 } if (!File.Exists(localPath + "/" + RootAssetsName)) //当本地依赖信息不存在时,更新 { isNeedUpdate = true; } else //总的依赖信息存在切文件已存在 对比本地和服务器两个文件的Hash值 { if (hash128Server == new Hash128(0, 0, 0, 0)) { return(true); //保证每次都下载总依赖文件 } hash128Local = assetBundleManifestLocal.GetAssetBundleHash(AssetName); //对比本地与服务器上的AssetBundleHash 版本不一致就下载 if (hash128Local != hash128Server) { isNeedUpdate = true; } } return(isNeedUpdate); }
IEnumerator Start() { //manifestをロード using (WWW www = new WWW(path + manifestName)) { yield return(www); if (!string.IsNullOrEmpty(www.error)) { Debug.Log(www.error); yield break; } manifest = (AssetBundleManifest)www.assetBundle.LoadAsset("AssetBundleManifest"); yield return(null); www.assetBundle.Unload(false); } //sceneをロード using (WWW www = WWW.LoadFromCacheOrDownload(path + bundleName, manifest.GetAssetBundleHash(bundleName))) { yield return(www); if (!string.IsNullOrEmpty(www.error)) { Debug.Log(www.error); yield break; } Application.LoadLevel(sceneName); yield return(null); www.assetBundle.Unload(false); } }
// Where we actuall call WWW to download the assetBundle. static protected bool LoadAssetBundleInternal (string assetBundleName, bool isLoadingAssetBundleManifest) { // Already loaded. LoadedAssetBundle bundle = null; m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle); if (bundle != null) { bundle.m_ReferencedCount++; if ( bundle.m_AssetBundle != null ) { return true; } return false; } WWW download = null; string url = m_BaseDownloadingURL + assetBundleName; // For manifest assetbundle, always download it as we don't have hash for it. if (isLoadingAssetBundleManifest) download = new WWW(url); else download = WWW.LoadFromCacheOrDownload(url, m_AssetBundleManifest.GetAssetBundleHash(assetBundleName), 0); m_LoadedAssetBundles.Add( assetBundleName, new LoadedAssetBundle( download ) ); return false; }
/// <summary> /// 实际下载的操作,返回值为真时,表示已经加载完成 /// </summary> private bool DownloadAssetBundleInternal(string assetBundleName, bool isLoadingAssetBundleManifest) { //已经下载过了 AssetBundleInfo bundle = null; _downloadedAssetBundles.TryGetValue(assetBundleName, out bundle); if (bundle != null) { bundle.m_ReferencedCount++; return(true); } if (_downloadingWWWs.ContainsKey(assetBundleName)) { return(true); } WWW download = null; string url = _downloadingURL + assetBundleName; DebugConsole.Log("[DownloadAssetBundle]:" + url); if (isLoadingAssetBundleManifest) { download = new WWW(url); } else { download = WWW.LoadFromCacheOrDownload(url, _assetBundleManifest.GetAssetBundleHash(assetBundleName), 0); } _downloadingWWWs.Add(assetBundleName, download); return(false); }
IObservable <AssetBundleCache> GetAssetBundleCache(string bundleName) { return(Observable.Defer(() => { AssetBundleCache assetBundleCache; if (_assetBundleCacheDict.TryGetValue(bundleName, out assetBundleCache)) { return Observable.Return <AssetBundleCache>(assetBundleCache); } LoadingCache <AssetBundleCache> loadingCache = null; if (!_loadingCacheDict.TryGetValue(bundleName, out loadingCache)) { loadingCache = new LoadingCache <AssetBundleCache>(); _loadingCacheDict.Add(bundleName, loadingCache); var url = Path.Combine(_cdn, bundleName); var hash = _manifest.GetAssetBundleHash(bundleName); var request = hash.isValid ? UnityWebRequestAssetBundle.GetAssetBundle(url, hash, 0) : UnityWebRequestAssetBundle.GetAssetBundle(url); request.SendAsObserable() .Select(operation => operation.webRequest).LoadAssetBundle() .Select(bundle => new AssetBundleCache(bundleName, bundle)) .Do(bundleCache => { _assetBundleCacheDict.Add(bundleName, bundleCache); _loadingCacheDict.Remove(bundleName); }) .Subscribe(loadingCache); } return loadingCache.ToLoadingObserable(); })); }
public void Export() { List <AssetBundleBuild> list = new List <AssetBundleBuild>(); //标记所有 asset bundle name var all = AssetBundleUtil.GetAll(); for (int i = 0; i < all.Count; i++) { AssetTarget target = all[i]; if (target.needSelfExport) { AssetBundleBuild build = new AssetBundleBuild(); build.assetBundleName = target.bundleName; build.assetNames = new string[] { target.assetPath }; list.Add(build); } } string bundleSavePath = AssetBundleUtil.GetBundleDir(); //开始打包 BuildPipeline.BuildAssetBundles(bundleSavePath, list.ToArray(), BuildAssetBundleOptions.UncompressedAssetBundle, EditorUserBuildSettings.activeBuildTarget); AssetBundle ab = AssetBundle.LoadFromFile(bundleSavePath + "/AssetBundles"); AssetBundleManifest manifest = ab.LoadAsset("AssetBundleManifest") as AssetBundleManifest; //hash for (int i = 0; i < all.Count; i++) { AssetTarget target = all[i]; if (target.needSelfExport) { Hash128 hash = manifest.GetAssetBundleHash(target.bundleName); if (target.bundleCrc != hash.ToString()) { if (AssetBundleBuildPanel.ABUpdateOpen) { string savePath = Path.Combine(Path.GetTempPath(), target.bundleName); string downloadPath = Path.Combine(Path.Combine(AssetBundleBuildPanel.TargetFolder, "AssetBundles"), target.bundleName); File.Copy(savePath, downloadPath, true); XMetaResPackage pack = new XMetaResPackage(); pack.buildinpath = target.bundleShortName; pack.download = string.Format("AssetBundles/{0}", target.bundleName); pack.Size = (uint)(new FileInfo(downloadPath)).Length; if (pack.Size != (new FileInfo(downloadPath)).Length) { EditorUtility.DisplayDialog("Bundle ", target.bundleShortName + " is lager than UINTMAX!!!", "OK"); } AssetBundleBuildPanel.assetBundleUpdate.Add(pack); File.Copy(savePath, bundleSavePath, true); } } target.bundleCrc = hash.ToString(); } } SaveDepAll(all); ab.Unload(true); RemoveUnused(all); AssetDatabase.RemoveUnusedAssetBundleNames(); AssetDatabase.Refresh(); }
public void parseManifest(AssetBundleManifest manifest, string packDir) { clear(); string[] abs = manifest.GetAllAssetBundles(); // 这里已经是小写了,所以没有大小写问题 for (int i = 0; i < abs.Length; i++) { bool isDirectory = false; string res = getResName(abs[i], out isDirectory); XBundleInfo ainfo = new XBundleInfo(); ainfo.res = res; ainfo.isDirectory = isDirectory; ainfo.persistentData = false; ainfo.hash = manifest.GetAssetBundleHash(abs[i]); ainfo.dependList = new List <string>(manifest.GetAllDependencies(abs[i])); // 获取文件大小 ainfo.fileSize = XUtil.getFileSize(packDir + abs[i]); for (int j = 0; j < ainfo.dependList.Count; j++) { ainfo.dependList[j] = getResName(ainfo.dependList[j], out isDirectory); } _info.Add(ainfo.res, ainfo); } this.callDependAllSize(); }
private IEnumerator DownloadAssetBundle(string assetBundleName, uint crc) { var path = $"{downloadUrl}{assetBundleName}"; var hash = _assetBundleManifest.GetAssetBundleHash(assetBundleName); using (var request = UnityWebRequestAssetBundle.GetAssetBundle(path, hash, crc)) { request.SendWebRequest(); while (request.isDone == false) { currentAssetBundleProgress = request.downloadProgress; currentAssetBundleSize = request.downloadedBytes; yield return(null); } if (string.IsNullOrEmpty(request.error) == false) { Debug.LogError($"[DownloadAssetBundle] Network Error! - {assetBundleName} / {crc}\n{request.error}"); state = STATE.ERROR; yield break; } var bundle = DownloadHandlerAssetBundle.GetContent(request); _assetBundleList.Add(assetBundleName, bundle); ++downloadedAssetBundleCount; Debug.Log($"[DownloadAssetBundle] Succeeded to download - {assetBundleName} / {crc}"); } }
// Where we actuall call WWW to download the assetBundle. static protected bool LoadAssetBundleInternal (string assetBundleName, bool isLoadingAssetBundleManifest) { // Already loaded. LoadedAssetBundle bundle = null; m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle); if (bundle != null) { bundle.m_ReferencedCount++; return true; } // @TODO: Do we need to consider the referenced count of WWWs? // In the demo, we never have duplicate WWWs as we wait LoadAssetAsync()/LoadLevelAsync() to be finished before calling another LoadAssetAsync()/LoadLevelAsync(). // But in the real case, users can call LoadAssetAsync()/LoadLevelAsync() several times then wait them to be finished which might have duplicate WWWs. if (m_DownloadingWWWs.ContainsKey(assetBundleName) ) return true; WWW download = null; string url = m_BaseDownloadingURL + assetBundleName; // For manifest assetbundle, always download it as we don't have hash for it. if (isLoadingAssetBundleManifest) download = new WWW(url); else download = WWW.LoadFromCacheOrDownload(url, m_AssetBundleManifest.GetAssetBundleHash(assetBundleName), 0); m_DownloadingWWWs.Add(assetBundleName, download); return false; }
public void InitByManifest(AssetBundleManifest assetBundleManifest, PackageManifest packageManifest) { assetLocations.Clear(); this.bundles.Clear(); mainBundles.Clear(); foreach (var bundle in packageManifest.Bundles) { var mainBundle = new MainBundle { Assets = bundle.Assets, Name = bundle.Name, Hash = assetBundleManifest.GetAssetBundleHash(bundle.Name) }; mainBundles.Add(mainBundle); this.bundles.Add(bundle.Name, mainBundle); } foreach (var asset in packageManifest.Assets) { assetLocations.Add(asset.Name, asset.Location); } string[] bundles = assetBundleManifest.GetAllAssetBundles(); foreach (var name in bundles) { if (!this.bundles.ContainsKey(name)) { AssetBundleInfo bundleInfo = new AssetBundleInfo { Name = name, Hash = assetBundleManifest.GetAssetBundleHash(name) }; this.bundles.Add(name, bundleInfo); } } foreach (var kv in this.bundles) { string[] depens = assetBundleManifest.GetAllDependencies(kv.Key); foreach (var dep in depens) { if (this.bundles.TryGetValue(dep, out var info)) { kv.Value.Dependencies.Add(info); } } } }
/// <summary> /// ハッシュ直取得 /// </summary> public static Hash128 TryGetHash(this AssetBundleManifest self, string abName) { if (!self) { return(new Hash128()); } return(self.GetAssetBundleHash(abName)); }
/// <summary> /// 获取AssetBundleHash 到字典中 /// </summary> /// <param name="a"></param> /// <param name="aDir"></param> public void GetHash128ToDicByAssetBundleManifest(AssetBundleManifest a, Dictionary <string, Hash128> aDir) { string[] aName = a.GetAllAssetBundles(); foreach (string name in aName) { aDir.Add(name, a.GetAssetBundleHash(name)); } }
public static string GetMD5InManifest(AssetBundleManifest rManifest, string rABName) { if (rManifest == null) { return(string.Empty); } return(rManifest.GetAssetBundleHash(rABName).ToString()); }
public Hash128 GetAssetBundleHash(string name) { if (manifest && assetBundlesNames.ContainsKey(name)) { return(manifest.GetAssetBundleHash(name)); } return(default(Hash128)); }
IEnumerator OnLoadAssetBundle(string abName, Type type) { string url = m_BaseDownloadingURL + abName; List <LoadAssetRequest> requests = null; if (!m_LoadRequests.TryGetValue(abName, out requests)) { LoadAssetRequest request = new LoadAssetRequest(); request.assetType = null; request.assetNames = new string[0] { }; request.luaFunc = null; request.sharpFunc = null; requests = new List <LoadAssetRequest>(); requests.Add(request); m_LoadRequests.Add(abName, requests); } WWW download = null; if (type == typeof(AssetBundleManifest)) { download = new WWW(url); } else { string[] dependencies = m_AssetBundleManifest.GetAllDependencies(abName); if (dependencies.Length > 0) { m_Dependencies.Add(abName, dependencies); for (int i = 0; i < dependencies.Length; i++) { string depName = dependencies[i]; AssetBundleInfo bundleInfo = null; if (m_LoadedAssetBundles.TryGetValue(depName, out bundleInfo)) { continue; } else if (!m_LoadRequests.ContainsKey(depName)) { //yield return StartCoroutine(OnLoadAssetBundle(depName, type)); yield return(StartCoroutine(OnLoadAsset <GameObject>(depName))); } } } download = WWW.LoadFromCacheOrDownload(url, m_AssetBundleManifest.GetAssetBundleHash(abName), 0); } yield return(download); AssetBundle assetObj = download.assetBundle; if (assetObj != null) { m_LoadedAssetBundles.Add(abName, new AssetBundleInfo(assetObj)); } }
IEnumerator OnLoadAssetBundle(string abName, Type type) { string url = m_BaseDownloadingURL + abName; WWW download = null; if (type == typeof(AssetBundleManifest)) { download = new WWW(url); } else { string[] dependencies = m_AssetBundleManifest.GetAllDependencies(abName); //获取该bundle的引用bundle if (dependencies.Length > 0) { if (m_Dependencies.ContainsKey(abName) == false) { m_Dependencies.Add(abName, dependencies); } for (int i = 0; i < dependencies.Length; i++) { string depName = dependencies[i]; AssetBundleInfo bundleInfo = null; if (m_LoadedAssetBundles.TryGetValue(depName, out bundleInfo)) { bundleInfo.m_ReferencedCount++; } else if (!m_LoadRequests.ContainsKey(depName)) { if (m_loadingRequests.ContainsKey(depName)) { m_loadingRequests[depName]++; } else { m_loadingRequests.Add(depName, 1); yield return(StartCoroutine(OnLoadAssetBundle(depName, type))); } } } } download = WWW.LoadFromCacheOrDownload(url, m_AssetBundleManifest.GetAssetBundleHash(abName), 0); } yield return(download); AssetBundle assetObj = download.assetBundle; if (assetObj != null) { m_LoadedAssetBundles.Add(abName, new AssetBundleInfo(assetObj)); if (m_loadingRequests.ContainsKey(abName)) { m_LoadedAssetBundles[abName].m_ReferencedCount = m_loadingRequests[abName]; m_loadingRequests.Remove(abName); } } }
/// <summary> /// 加载资源集合 /// </summary> /// <returns></returns> IEnumerator RealLoad(string assetBundle, System.Action callback, bool loadCommon = false) { yield return(DownloadManifest(PUBLIC_PATH_DEFINE.AssetBundlesManifestPath)); if (manifest == null) { DebugConsole.LogError("BundleAssetProvider Error : Can't Load AssetBundle Manifest\r\nFile Path = " + PUBLIC_PATH_DEFINE.AssetBundlesManifestPath); yield break; } string[] allToLoad = GetAllBundlesOrderByDependency(assetBundle); DebugConsole.Log("all to load length = " + allToLoad.Length, DebugConsole.Color.yellow); foreach (string toLoad in allToLoad) { if (CheckBundleLoaded(toLoad)) //不要重复加载同一AssetBundle { continue; } DebugConsole.Log("bundleName = " + toLoad, DebugConsole.Color.green); string url = urlbase + toLoad; Hash128 hash = manifest.GetAssetBundleHash(toLoad); WWW www = WWW.LoadFromCacheOrDownload(url, hash); yield return(www); if (string.IsNullOrEmpty(www.error)) { AssetBundle bundle = www.assetBundle; if (!loadCommon) { packageBundles.Add(toLoad, bundle); } else { commonBundles.Add(toLoad, bundle); } } else { DebugConsole.LogError("RealLoad AssetBundle => WWW Error = " + www.error); } } if (callback != null) { try { DebugConsole.Log("Load All Bundles Done!"); callback.Invoke(); } catch (System.Exception ex) { DebugConsole.LogError("Load Bundles Invoke Error!"); DebugConsole.LogError(ex.Message); DebugConsole.LogError(ex.StackTrace); } } }
private void DownloadBundle(string bundleName, Action <AssetBundle> callback) { if (bundleName.IsValidText()) { string remapName = RemapVariantName(bundleName); if (DownloadedBundle(remapName).IsNull()) { Hash128 hash = m_AssetManifest.GetAssetBundleHash(remapName); AssetBundleDownloader downloader = new AssetBundleDownloader(BaseUri, remapName, hash, (bundle) => { InsertBundle(remapName, bundle); callback(bundle); }); StartCoroutine(downloader.Download()); } else { callback(DownloadedBundle(remapName)); } } else { callback(null); } }
public static Hash128 GetHash(string bundleName) { if (!s_isInit) { Initialize(); } return(s_manifest.GetAssetBundleHash(bundleName)); }
public override void SetManifest(AssetBundleManifest obj) { foreach (var v in obj.GetAllAssetBundles()) { _allHashes.Add(v, obj.GetAssetBundleHash(v)); } base.SetManifest(obj); }
//アセットバンドルマニフェストから作成 public ConvertFileInfo(string name, AssetBundleManifest manifest, ConvertFileInfoDictionary list) { this.Name = name; this.Version = 0; this.Hash = manifest.GetAssetBundleHash(name); this.AllDependencies = manifest.GetAllDependencies(name); this.DirectDependencies = manifest.GetDirectDependencies(name); this.List = list; }
/// <summary> /// 获取当前总的Manifest中所有的AssetBundle名称与其HashID的对应集合 /// </summary> public void GetBundleNamesAndHashID() { string[] assetBundleNames = manifest.GetAllAssetBundles(); //所有的资源包名称 for (int i = 0; i < assetBundleNames.Length; i++) { DictBundleNamesHashID.Add(assetBundleNames[i], manifest.GetAssetBundleHash(assetBundleNames[i]).ToString()); } }
private void InitBundleHashCode(AssetBundleManifest manifest) { string[] bundles = manifest.GetAllAssetBundles(); m_BundleHashCode = new Dictionary <string, Hash128>(); for (int i = 0; i < bundles.Length; i++) { m_BundleHashCode.Add(bundles[i], manifest.GetAssetBundleHash(bundles[i])); } }
// 유틸 : 번들 패킹 시작 및 아웃풋 static bool MakeAssetBundle(BuildTarget eTarget, string strOutputPath, Dictionary <string, AssetBundleInfo> dicBundles) { // 디렉토리 정리 SHUtils.DeleteDirectory(strOutputPath); SHUtils.CreateDirectory(strOutputPath); // 번들 빌드 정보 만들기 List <AssetBundleBuild> pBuildList = new List <AssetBundleBuild>(); SHUtils.ForToDic(dicBundles, (pKey, pValue) => { List <string> pAssets = new List <string>(); SHUtils.ForToDic(pValue.m_dicResources, (pResKey, pResValue) => { pAssets.Add(string.Format("{0}/{1}{2}", "Assets/Resources", pResValue.m_strPath, pResValue.m_strExtension)); }); AssetBundleBuild pAssetInfo = new AssetBundleBuild(); pAssetInfo.assetBundleName = string.Format("{0}.unity3d", pValue.m_strBundleName); pAssetInfo.assetNames = pAssets.ToArray(); pBuildList.Add(pAssetInfo); }); // 빌드할 번들이 없으면 종료 if (0 == pBuildList.Count) { return(true); } // 번들 빌드하기 AssetBundleManifest pManifest = BuildPipeline.BuildAssetBundles(strOutputPath, pBuildList.ToArray(), BuildAssetBundleOptions.DeterministicAssetBundle, eTarget); if (null == pManifest) { Debug.LogErrorFormat("Error!!! Make Assets Bundle : {0}", strOutputPath); return(false); } // 후 처리 SHUtils.ForToList(pBuildList, (pBundle) => { // 번들 크기와 해시코드 기록 string strKey = pBundle.assetBundleName.Substring(0, pBundle.assetBundleName.Length - ".unity3d".Length).ToLower(); if (true == dicBundles.ContainsKey(strKey)) { dicBundles[strKey].m_pHash128 = pManifest.GetAssetBundleHash(pBundle.assetBundleName); dicBundles[strKey].m_lBundleSize = (new FileInfo(string.Format("{0}/{1}", strOutputPath, pBundle.assetBundleName))).Length; } // Manifest제거 ( 사용하지 않는 불필요한 파일이라 그냥 제거시킴 ) SHUtils.DeleteFile(string.Format("{0}/{1}.manifest", strOutputPath, pBundle.assetBundleName)); }); SHUtils.DeleteFile(string.Format("{0}/{1}", strOutputPath, SHHard.GetStrToPlatform(eTarget))); SHUtils.DeleteFile(string.Format("{0}/{1}.manifest", strOutputPath, SHHard.GetStrToPlatform(eTarget))); return(true); }
/// <summary> /// CoreABDownloader is BOTH AssetBundle DOWNLOADER and USER /// It checks AB_Hash with Cache then download Latest AB if it has to /// </summary> /// <param name="_fileURL"></param> /// <param name="_success"></param> /// <param name="_fail"></param> /// <param name="_progress"></param> IEnumerator CoreABDownloader(ABFileURL _fileURL, Action <UnityWebRequest> _success = null, Action <string> _fail = null, Action <float> _progress = null) { if (myABM == null) { Debug.LogError("ABM not loaded!"); } Hash128 abHash = myABM.GetAssetBundleHash(_fileURL.fileName); //Clean up older AB in Cache Caching.ClearOtherCachedVersions(_fileURL.fileName, abHash); Debug.Log("Try to Download " + _fileURL); #if UNITY_2018_1_OR_NEWER using (var _uwr = UnityWebRequestAssetBundle.GetAssetBundle(_fileURL.fullURL, abHash, 0)) #else using (var _uwr = UnityWebRequest.GetAssetBundle(_fileURL.fullURL, abHash, 0)) #endif { _uwr.SendWebRequest(); yield return(null); while (!_uwr.isDone) { if (_progress != null) { _progress(_uwr.downloadProgress); } yield return(null); } if (_uwr.isNetworkError || _uwr.isHttpError) { Debug.LogError("File Download Failed " + _uwr.error); if (_fail != null) { _fail(_uwr.error); } } else { if (_success != null) { _success(_uwr); } } yield return(null); yield return(null); yield return(null); } }
public static Hash128 GetAssetBundleHash(string bundleName) { if (m_AssetBundleManifest == null) { Log(AssetSetting.LogType.Error, "Please initialize AssetBundleManifest by calling AssetBundleManager.Initialize()"); return(new Hash128()); } return(m_AssetBundleManifest.GetAssetBundleHash(bundleName)); }
static void BuildAllAssetBundles() { string assetBundleDirectory = "Assets/AssetBundles/"; Directory.CreateDirectory(assetBundleDirectory); if (!Directory.Exists(assetBundleDirectory)) { Directory.CreateDirectory(assetBundleDirectory); } AssetBundleManifest assetMf = BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.StandaloneWindows); //CRC uint cardsCRC; uint cardsetsCRC; BuildPipeline.GetCRCForAssetBundle(assetBundleDirectory + "cards", out cardsCRC); BuildPipeline.GetCRCForAssetBundle(assetBundleDirectory + "cardsets", out cardsetsCRC); Debug.LogFormat("cards CRC: {0}", cardsCRC); Debug.LogFormat("cardsets CRC: {0}", cardsetsCRC); //Hash128 Hash128 cardsHash128 = assetMf.GetAssetBundleHash("cards"); Hash128 cardsetsHash128 = assetMf.GetAssetBundleHash("cardsets"); Debug.LogFormat("cards Hash128: {0}", cardsHash128); Debug.LogFormat("cardsets Hash128: {0}", cardsetsHash128); //Save to manifest JSONNode N = new JSONObject(); N["cards_hash128"] = cardsHash128.ToString(); N["cardsets_hash128"] = cardsetsHash128.ToString(); N["cards_crc"] = cardsCRC; N["cardsets_crc"] = cardsetsCRC; File.WriteAllText(assetBundleDirectory + "manifest.json", JsonHelper.FormatJson(N.ToString())); File.Delete(assetBundleDirectory + "CardText"); File.Delete(assetBundleDirectory + "CardText.manifest"); File.Delete(assetBundleDirectory + "CardText.manifest.meta"); File.Delete(assetBundleDirectory + "CardText.meta"); CardsCount(); }