public void BuildAssetBundle(bool clearOldBundle) { Debug.LogWarning("BuildAssetBundle-----------------------------------"); //*****************读取以前列表文件信息******************** string manifest = BundleTools.GetBuildBundlePath(isStaticAsset) + "/" + assetFileTool; localManifest = AssetFileTool.LoadFromFile(manifest); BundleTools.CreateBuildBundleDir(isStaticAsset); if (clearOldBundle) { BundleTools.ClearBuildBundleDir(isStaticAsset); } BuildTarget platform = EditorUserBuildSettings.activeBuildTarget; BuildAssetBundleOptions babo = BuildAssetBundleOptions.ChunkBasedCompression; System.DateTime dt = System.DateTime.Now; string targetPath = BundleTools.GetBuildBundlePath(isStaticAsset); BuildPipeline.BuildAssetBundles(targetPath, babo, platform); Debug.Log("Build bundle cost time: " + (DateTime.Now - dt).TotalSeconds + "s"); AssetBundleNameSet.ClearAllBundleName(); //清除 AssetDatabase.Refresh(); }
private void CopyFileToProject(string sourceName, string targetName, bool resourceDir, bool streamAssets) { //获取资源列表 string path = BundleTools.GetBuildBundlePath(isStaticAsset) + "/" + sourceName; if (streamAssets) { Debug.Log("############### 拷贝资源列表到工程StreamingAssets目录 ###############"); string streamingAssetManiPath = Application.streamingAssetsPath + "/" + BundleTools.GetABManefistName() + "/"; //创建StreamingAssets下的文件夹 if (!Directory.Exists(streamingAssetManiPath)) { Directory.CreateDirectory(streamingAssetManiPath); } //拷贝assetManifest文件到streamingAsset if (File.Exists(streamingAssetManiPath + targetName)) { File.Delete(streamingAssetManiPath + targetName); } File.Copy(path, streamingAssetManiPath + targetName, true); } if (resourceDir) { //拷贝assetManifest文件到Resources string resourceAssetMainPath = Application.dataPath + "/Resources/BundleList/" + BundleTools.GetABManefistName() + "/"; //创建StreamingAssets下的文件夹 if (!Directory.Exists(resourceAssetMainPath)) { Directory.CreateDirectory(resourceAssetMainPath); } if (File.Exists(resourceAssetMainPath + targetName)) { File.Delete(resourceAssetMainPath + targetName); } File.Copy(path, resourceAssetMainPath + targetName, true); } AssetDatabase.Refresh(); }
//生成主资源列表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); }