public List <string> CompareTo(Manifest otherManifest) { List <string> ret_list = new List <string>(); if (otherManifest == null || otherManifest.assetbundleManifest == null) { return(ret_list); } string[] other_name_list = otherManifest.GetAllAssetBundleNames(); string[] self_name_list = GetAllAssetBundleNames(); foreach (string name in other_name_list) { int idx = System.Array.FindIndex(self_name_list, element => element.Equals(name)); if (idx == -1) { //对方有、自己无 ret_list.Add(name); } else if (!GetAssetBundleHash(self_name_list[idx]).Equals(otherManifest.GetAssetBundleHash(name))) { //对方有,自己有,但是hash不同 ret_list.Add(name); } else { //对方有,自己有,且hash相同:什么也不做 //donothing } } return(ret_list); }
public IEnumerator Initialize() { #if UNITY_EDITOR if (AssetBundleConfig.IsEditorMode) { yield break; } #endif manifest = new Manifest(); assetsPathMapping = new AssetsPathMapping(); // 说明:同时请求资源可以提高加载速度 var manifestRequest = RequestAssetBundleAsync(manifest.AssetbundleName); var pathMapRequest = RequestAssetBundleAsync(assetsPathMapping.AssetbundleName); yield return manifestRequest; var assetbundle = manifestRequest.assetbundle; manifest.LoadFromAssetbundle(assetbundle); assetbundle.Unload(false); manifestRequest.Dispose(); yield return pathMapRequest; assetbundle = pathMapRequest.assetbundle; var mapContent = assetbundle.LoadAsset<TextAsset>(assetsPathMapping.AssetName); if (mapContent != null) { assetsPathMapping.Initialize(mapContent.text); } assetbundle.Unload(true); pathMapRequest.Dispose(); // 设置所有公共包为常驻包 var start = DateTime.Now; var allAssetbundleNames = manifest.GetAllAssetBundleNames(); foreach (var curAssetbundleName in allAssetbundleNames) { if (string.IsNullOrEmpty(curAssetbundleName)) { continue; } int count = 0; foreach (var checkAssetbundle in allAssetbundleNames) { if (checkAssetbundle == curAssetbundleName || string.IsNullOrEmpty(checkAssetbundle)) { continue; } var allDependencies = manifest.GetAllDependencies(checkAssetbundle); if (Array.IndexOf(allDependencies, curAssetbundleName) >= 0) { count++; if (count >= 2) { break; } } } // 说明:设置被依赖数量为1的AB包为常驻包的理由详细情况见AssetBundleAsyncLoader.cs那一大堆注释 // TODO:1)目前已知Unity5.3版本和Unity5.5版本没问题,其它试过的几个版本都有问题,如果你使用的版本也有问题,需要修改这里的宏 // 2)整套AB包括压缩格式可能都要重新设计,这个以后有时间再去尝试 #if !UNITY_5_3 && !UNITY_5_5 if (count >= 1) #else if (count >= 2) #endif { SetAssetBundleResident(curAssetbundleName, true); } } Logger.Log(string.Format("AssetBundleResident Initialize use {0}ms", (DateTime.Now - start).Milliseconds)); IsInitialized = true; yield break; }
public IEnumerator Initialize() { #if UNITY_EDITOR if (AssetBundleConfig.IsEditorMode) { yield break; } #endif manifest = new Manifest(); assetsPathMapping = new AssetsPathMapping(); // 说明:同时请求资源可以提高加载速度 var manifestRequest = RequestAssetBundleAsync(manifest.AssetbundleName); var pathMapRequest = RequestAssetBundleAsync(assetsPathMapping.AssetbundleName); yield return(manifestRequest); var assetbundle = manifestRequest.assetbundle; manifest.LoadFromAssetbundle(assetbundle); assetbundle.Unload(false); manifestRequest.Dispose(); yield return(pathMapRequest); assetbundle = pathMapRequest.assetbundle; var mapContent = assetbundle.LoadAsset <TextAsset>(assetsPathMapping.AssetName); if (mapContent != null) { assetsPathMapping.Initialize(mapContent.text); } assetbundle.Unload(true); pathMapRequest.Dispose(); // 设置所有公共包为常驻包 var start = DateTime.Now; var allAssetbundleNames = manifest.GetAllAssetBundleNames(); foreach (var curAssetbundleName in allAssetbundleNames) { if (string.IsNullOrEmpty(curAssetbundleName)) { continue; } int count = 0; foreach (var checkAssetbundle in allAssetbundleNames) { if (checkAssetbundle == curAssetbundleName || string.IsNullOrEmpty(checkAssetbundle)) { continue; } var allDependencies = manifest.GetAllDependencies(checkAssetbundle); if (Array.IndexOf(allDependencies, curAssetbundleName) >= 0) { count++; if (count >= 2) { break; } } } if (count >= 2) { SetAssetBundleResident(curAssetbundleName, true); } } Logger.Log(string.Format("AssetBundleResident Initialize use {0}ms", (DateTime.Now - start).Milliseconds)); yield break; }