public static void Execute(UnityEditor.BuildTarget target) { string SavePath = BuildPipelinePanel.GetPlatformReleasePath(target); // 当前选中的资源列表 foreach (Object o in Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets)) { string path = AssetDatabase.GetAssetPath(o); //string [] levels = {path}; // 过滤掉meta文件和文件夹 if (path.Contains(".meta") || path.Contains(".") == false) { continue; } // 过滤掉UIAtlas目录下的贴图和材质(UI/Common目录下的所有资源都是UIAtlas) if (path.Contains("UI/Common")) { if ((o is Texture) || (o is Material)) { continue; } } path = SavePath + ConvertToAssetBundleName(path); path = path.Substring(0, path.LastIndexOf('.')); path += ".assetbundle"; //打包场景 //BuildPipeline.BuildStreamedSceneAssetBundle (levels, path, target, BuildOptions.UncompressedAssetBundle); } // scene目录下的资源 AssetDatabase.Refresh(); }
private void ReleaseFile(BuildTarget target, string fileName) { string path = Path.Combine(SAAppConfig.DevResDir, SAAppConfig.DataDir) + fileName; FileInfo fileInfo = new FileInfo(path); string AbsReleasePath = BuildPipelinePanel.GetPlatformAbsReleasePath(target); SALang.MakDirValid(AbsReleasePath); path = Path.Combine(AbsReleasePath, fileName); SALang.ForceDeleteFile(path); fileInfo.CopyTo(path); }
// 对比对应版本目录下的VersionMD5和VersionMD5-old,得到最新的版本号文件VersionNum.xml public static bool Execute(BuildTarget target) { string platform = SAAppConfig.Language + BuildPipelinePanel.GetPlatformName(target); // 读取新旧MD5列表 string newVersionMD5 = System.IO.Path.Combine(Application.dataPath, "AssetBundle/" + platform + "/VersionMD5.xml"); string oldVersionMD5 = System.IO.Path.Combine(Application.dataPath, "AssetBundle/" + platform + "/VersionMD5-old.xml"); Dictionary <string, string> dicNewMD5Info = ReadMD5File(newVersionMD5); Dictionary <string, string> dicOldMD5Info = ReadMD5File(oldVersionMD5); // 读取版本号记录文件VersinNum.xml string oldVersionNum = System.IO.Path.Combine(Application.dataPath, "AssetBundle/" + platform + "/VersionNum.xml"); Dictionary <string, int> dicVersionNumInfo = ReadVersionNumFile(oldVersionNum); // 对比新旧MD5信息,并更新版本号,即对比dicNewMD5Info&&dicOldMD5Info来更新dicVersionNumInfo foreach (KeyValuePair <string, string> newPair in dicNewMD5Info) { // 旧版本中有 if (dicOldMD5Info.ContainsKey(newPair.Key)) { // MD5一样,则不变 // MD5不一样,则+1 // 容错:如果新旧MD5都有,但是还没有版本号记录的,则直接添加新纪录,并且将版本号设为1 if (dicVersionNumInfo.ContainsKey(newPair.Key) == false) { dicVersionNumInfo.Add(newPair.Key, 1); } else if (newPair.Value != dicOldMD5Info[newPair.Key]) { int num = dicVersionNumInfo[newPair.Key]; dicVersionNumInfo[newPair.Key] = num + 1; } } else // 旧版本中没有,则添加新纪录,并=1 { if (dicVersionNumInfo.ContainsKey(newPair.Key) == false) { dicVersionNumInfo.Add(newPair.Key, 1); } } } // 不可能出现旧版本中有,而新版本中没有的情况,原因见生成MD5List的处理逻辑 // 存储最新的VersionNum.xml SaveVersionNumFile(dicVersionNumInfo, oldVersionNum); AssetDatabase.Refresh(); return(true); }
public static bool Execute(BuildTarget target) { string platform = SAAppConfig.Language + BuildPipelinePanel.GetPlatformName(target); Dictionary <string, string> DicFileMD5 = new Dictionary <string, string>(); MD5CryptoServiceProvider md5Generator = new MD5CryptoServiceProvider(); string dir = Path.Combine(SAAppConfig.ReleasePath, platform); foreach (string filePath in Directory.GetFiles(dir)) { if (filePath.Contains(".meta") || filePath.Contains(".u") || filePath.Contains("VersionMD5") || filePath.Contains(".xml") || filePath.Contains(".DS_Store")) { continue; } setVersionToDictionary(dir, platform + "/", filePath, DicFileMD5, md5Generator); } dir += "s"; foreach (string filePath in Directory.GetFiles(dir)) { if (filePath.Contains(".meta") || filePath.Contains(".u") || filePath.Contains("VersionMD5") || filePath.Contains(".xml") || filePath.Contains(".DS_Store")) { continue; } setVersionToDictionary(dir, platform + "s/", filePath, DicFileMD5, md5Generator); } //lua file // string luaPath = Path.Combine(SAAppConfig.ReleasePath, Path.Combine(SAAppConfig.LuaPath, SAAppConfig.LuaPathName)); // dir = Path.Combine(SAAppConfig.ReleasePath, SAAppConfig.LuaPath); // setVersionToDictionary(dir, luaPath, DicFileMD5, md5Generator); string savePath = Path.Combine(Application.dataPath, "AssetBundle/") + platform; if (Directory.Exists(savePath) == false) { Directory.CreateDirectory(savePath); } // 删除前一版的old数据 if (File.Exists(savePath + "/VersionMD5-old.xml")) { System.IO.File.Delete(savePath + "/VersionMD5-old.xml"); } // 如果之前的版本存在,则将其名字改为VersionMD5-old.xml if (File.Exists(savePath + "/VersionMD5.xml")) { System.IO.File.Move(savePath + "/VersionMD5.xml", savePath + "/VersionMD5-old.xml"); } XmlDocument XmlDoc = new XmlDocument(); XmlElement XmlRoot = XmlDoc.CreateElement("Files"); XmlDoc.AppendChild(XmlRoot); foreach (KeyValuePair <string, string> pair in DicFileMD5) { XmlElement xmlElem = XmlDoc.CreateElement("File"); XmlRoot.AppendChild(xmlElem); xmlElem.SetAttribute("FileName", pair.Key); xmlElem.SetAttribute("MD5", pair.Value); } // 读取旧版本的MD5 Dictionary <string, string> dicOldMD5 = ReadMD5File(savePath + "/VersionMD5-old.xml"); // VersionMD5-old中有,而VersionMD5中没有的信息,手动添加到VersionMD5 foreach (KeyValuePair <string, string> pair in dicOldMD5) { if (DicFileMD5.ContainsKey(pair.Key) == false) { DicFileMD5.Add(pair.Key, pair.Value); } } XmlDoc.Save(savePath + "/VersionMD5.xml"); XmlDoc = null; AssetDatabase.Refresh(); return(true); }
public static bool Execute(UnityEditor.BuildTarget target, BuildAssetBundleOptions bbo, string ext, string[] dirs, string[] extNames, bool fixedAssetName, string assetName) { string ReleasePath = BuildPipelinePanel.GetPlatformReleasePath(target, ext); //相对路径 string AbsReleasePath = BuildPipelinePanel.GetPlatformAbsReleasePath(target, ext); //绝对路径 SALang.MakDirValid(AbsReleasePath); string rootDir = SALang.NormalizePath(SAAppConfig.DevResDir);// 根目录 int dirLen = dirs.Length; int fileLen; int i = 0, j; string searchDir; string[] filePaths; List <string> files; string[] resourcesAssets; List <AssetBundleBuild> abbs = new List <AssetBundleBuild>(); AssetBundleBuild abb; string assetsFullPath; for (; i < dirLen; ++i) { searchDir = Path.Combine(rootDir, dirs[i]); filePaths = SALang.GetFileList(searchDir, extNames[i], true); if (null == filePaths || filePaths.Length == 0) { Debug.Log(string.Format("目录{0}没有需要打包的文件...", searchDir)); continue; } files = new List <string>(); files.AddRange(filePaths); fileLen = filePaths.Length; int languageDot; //所有文件 for (j = 0; j < fileLen; ++j) { string filename = SALang.NormalizePath(filePaths[j]); //绝对路径 if (filename.Substring(filename.LastIndexOf(".") + 1).Equals("meta")) //验证后缀 { continue; } assetsFullPath = filename.Replace(SAAppConfig.DevResDir, ""); //转换为相对路径 filename = ConvertToAssetBundleName(assetsFullPath).ToLower(); //转换为 languageDot = filename.LastIndexOf(".", filename.LastIndexOf(".") - 1); string language = filename.Substring(languageDot + 1, SAAppConfig.Language.Length); if (!language.Equals(SAAppConfig.Language)) { continue; } if (dirs[i].Equals(SAAppConfig.LuaByteDir) || dirs[i].Equals(SAAppConfig.DataDir)) { filename = filename.Substring(filename.IndexOf(".") + 1); assetsFullPath = Path.Combine(AbsReleasePath, filename); FileInfo fileInfo = new FileInfo(filePaths[j]); SALang.ForceDeleteFile(assetsFullPath); fileInfo.CopyTo(assetsFullPath, false); } else { //filename += ".sa"; resourcesAssets = new string[1]; resourcesAssets[0] = Path.Combine(SAAppConfig.LocalDevDir, assetsFullPath); DoSetAssetBundleName(filePaths[j] + ".meta", filename); abb = new AssetBundleBuild(); abb.assetBundleName = fixedAssetName ? assetName : filename; abb.assetNames = resourcesAssets; abbs.Add(abb); } } } BuildPipeline.BuildAssetBundles(ReleasePath, abbs.ToArray(), bbo, target); AssetDatabase.Refresh(); return(true); }