public static AssetFileTool CreateAssetFileByManifest(AssetBundleManifest manifest, int version, string baseAdd, AssetCell mainAc) { AssetFileTool aft = new AssetFileTool(); aft.version = version; aft.AddAsset(mainAc); string[] asets = manifest.GetAllAssetBundles(); for (int i = 0; i < asets.Length; ++i) { FileInfo fi = new FileInfo(baseAdd + asets[i]); //Hash128 h = manifest.GetAssetBundleHash(asets[i]); string hashCode = GetMD5HashFromFile(baseAdd + asets[i]); AssetCell ac = new AssetCell(asets[i], hashCode.ToString(), fi.Length); aft.AddAsset(ac); } return(aft); }
//文件在apk包内,需要用www加载,用www.text取得字符串 public static AssetFileTool LoadFromString(string data) { AssetFileTool aft = new AssetFileTool(); try { using (StringReader sr = new StringReader(data)) { aft.version = int.Parse(sr.ReadLine()); string line = sr.ReadLine(); aft.platform = line; while (line != null) { AssetCell ac = new AssetCell(); if (ac.ReadData(line)) { try { aft.assetCells.Add(ac.path, ac); } catch (Exception e) { Debug.Log(line + ": " + e.Message); } } else { Debug.LogWarning("Asset file error " + line); } line = sr.ReadLine(); } sr.Close(); } return(aft); } catch (System.Exception e) { Debug.LogError("Asset file load error " + e); return(null); } }
//文件在apk包外 public static AssetFileTool LoadFromFile(string path) { if (!File.Exists(path)) { Debug.LogError("Loaded asset is not exist. Path: " + path); return(null); } AssetFileTool aft = new AssetFileTool(); try { using (StreamReader sr = new StreamReader(File.OpenRead(path))) { aft.version = int.Parse(sr.ReadLine()); string line = sr.ReadLine(); aft.platform = line; while (line != null) { AssetCell ac = new AssetCell(); if (ac.ReadData(line)) { if (aft.assetCells.ContainsKey(ac.path)) { Debug.LogError("key repeat: " + ac.path); } aft.assetCells.Add(ac.path, ac); } line = sr.ReadLine(); } sr.Close(); } return(aft); } catch (System.Exception e) { Debug.LogError("Asset file load error " + e.Message); return(null); } }
//生成主资源列表assetmanifest public void BuildManifest() { string mainPath = BundleTools.GetBuildBundlePath(isStaticAsset) + "/" + mainfestName; AssetBundle ab = AssetBundle.LoadFromFile(mainPath); if (ab == null) { Debug.LogError("ab is null!"); return; } AssetCell mac = new AssetCell(); FileInfo fi = new FileInfo(mainPath); mac.path = mainfestName; mac.size = fi.Length; mac.hashCode = BundleTools.GetMD5HashFromFile(mainPath); mac.loadLevel = 0; AssetBundleManifest abm = ab.LoadAsset("assetbundlemanifest") as AssetBundleManifest; string[] des = abm.GetAllDependencies("ui/page/main_ui.ab"); foreach (var de in des) { Debug.LogWarning("de:" + de); } ab.Unload(false); //即将生成的列表 int versionNum = 0; if (isStaticAsset) { versionNum = StaticResVersion; } else if (buildEmptyDynamicAssets) { versionNum = 0; } else { versionNum = DynamicResVersion; } AssetFileTool aft = AssetFileTool.CreateAssetFileByManifest(abm, versionNum, BundleTools.GetBuildBundlePath(isStaticAsset) + "/", mac); List <AssetCell> unneceList; List <AssetCell> lackList; List <AssetCell> obbList; AssetFileTool.Compare(localManifest, aft, out unneceList, out lackList, out obbList); if (unneceList.Count != 0) { Debug.LogWarning("旧包中无用的bandle数据为:" + unneceList.Count); foreach (var cell in unneceList) { Debug.LogWarning(cell.path); } } if (lackList.Count != 0) { Debug.LogWarning("新增的bandle数据为:" + lackList.Count); foreach (var cell in lackList) { Debug.LogWarning(cell.path); } } if (obbList.Count != 0) { Debug.LogWarning("数据包需要更新的的bandle数据为:" + obbList.Count); foreach (var cell in obbList) { Debug.LogWarning(cell.path); } } string manifest = BundleTools.GetBuildBundlePath(isStaticAsset) + "/" + assetFileTool; if (File.Exists(manifest)) { File.Delete(manifest); } aft.SaveToFile(manifest); Debug.Log("生成资源列表文件已完成! " + assetFileTool); }
public static CGRect ContractingAnimationToCellRect(AssetListViewController toVC, AssetCell toCell) { var origin = new CGPoint( x: toCell.Frame.X, y: toCell.Frame.Y - toVC.CollectionView.ContentOffset.Y ); return(new CGRect(origin, toCell.Frame.Size)); }
public static CGRect ExpandingAnimationFromCellRect(AssetListViewController fromVC, AssetCell fromCell) { var origin = new CGPoint( x: fromCell.Frame.X, y: fromCell.Frame.Y - fromVC.CollectionView.ContentOffset.Y ); return(new CGRect(origin, fromCell.Frame.Size)); }
public void AddAsset(AssetCell ac) { assetCells.Add(ac.path, ac); }
public void AddAssetAndSave(AssetCell ac) { assetCells.Add(ac.path, ac); streamWriter.WriteLine(ac.ToString()); streamWriter.Flush(); }