public static void CreateEntryXmlFile() { string path = AssetBundlePath.GetAssetBundleEntryPath(); if (File.Exists(path)) { File.Delete(path); } try { EditorPlatformPath.CheckDirExistsForFile(path); XmlDocument document = new XmlDocument(); XmlDeclaration dec = document.CreateXmlDeclaration("1.0", "UTF-8", null); XmlElement root = document.CreateElement("root"); document.AppendChild(root); XmlElement mapping = document.CreateElement("AssetMappings"); mapping.SetAttribute("manifest", AssetBundlePath.GetManifestAssetBundlePath()); root.AppendChild(mapping); XmlWriterSettings setting = new XmlWriterSettings(); setting.Indent = true; setting.Encoding = new UTF8Encoding(false); XmlWriter write = XmlWriter.Create(path, setting); document.Save(write); write.Flush(); write.Close(); } catch (Exception e) { Debug.LogError(e); } }
private static void RemoveNonexistAssetBundleFiles() { string assetBundleDir = AssetBundlePath.GetAssetBundlePath(); if (!Directory.Exists(assetBundleDir)) { return; } //把所有会的bundle文件统计出来,再去检索已存在的bundle,把不存在的移除掉 List <AssetBundleBuildSearchInfo> allAssetBundleInfos = new List <AssetBundleBuildSearchInfo>(); foreach (AssetbundleBuildSearchGroupInfo group in AssetBundleConfig.GetAllGroupInfos()) { allAssetBundleInfos.AddRange(group.buildAssets); } HashSet <string> onlyMoveFileList = new HashSet <string>(); //以下不移除 onlyMoveFileList.Add(AssetBundlePath.GetAssetBundleEntryPath().Replace(assetBundleDir, "")); onlyMoveFileList.Add(AssetBundlePath.GetManifestAssetBundlePath()); onlyMoveFileList.Add(AssetBundlePath.GetManifestAssetBundlePath() + ".manifest"); HashSet <string> hasFilePaths = new HashSet <string>(); foreach (string s in buildResultInfo.onlyMoveFileList) { onlyMoveFileList.Add(s); } foreach (var build in buildResultInfo.needBuildList) { hasFilePaths.Add(assetBundleDir + build.assetBundleName); hasFilePaths.Add(assetBundleDir + build.assetBundleName + ".manifest"); hasFilePaths.Add(assetBundleDir + build.assetBundleName + ".meta"); hasFilePaths.Add(assetBundleDir + build.assetBundleName + ".manifest.meta"); } foreach (string path in onlyMoveFileList) { string p = path.Replace("\\", "/").Replace(AssetBundlePath.ProjectGameAssetsDirectory, "").ToLower(); hasFilePaths.Add(assetBundleDir + p); hasFilePaths.Add(assetBundleDir + p + ".meta"); } string[] files = Directory.GetFiles(assetBundleDir, "*.*", SearchOption.AllDirectories); foreach (string f in files) { string filePath = f.Replace("\\", "/"); if (!hasFilePaths.Contains(filePath)) { Debug.Log("移除不存在的历史Bundle>>" + filePath); File.Delete(filePath); } } EditorFileOperate.RemoveEmptyDir(assetBundleDir); AssetDatabase.Refresh(); }