static void GenerateIndexFile(string destDir, string language, string moduleName, string indexFileName, string releasePath, string packagePath, bool useSubDir = true, FileType fileType = FileType.Zip, bool ignoreItems = false) { releasePath = "AssetBundles/" + SystemTag + "/" + releasePath; ResIndex resIndex = new ResIndex(); resIndex.language = language; resIndex.belong = moduleName; resIndex.packageDict = new Dictionary <string, ResPack>(); string[] dirs = new string[] { destDir }; if (useSubDir) { dirs = Directory.GetDirectories(destDir); } for (int i = 0; i < dirs.Length; i++) { ResPack resPack = new ResPack(); resPack.id = new FileInfo(dirs[i]).Name; if (ignoreItems == false) { resPack.items = new List <ResItem>(); string[] files = Directory.GetFiles(dirs[i]); for (int j = 0; j < files.Length; j++) { string filePath = files[j]; FileInfo fileInfo = new FileInfo(filePath); ResItem resItem = new ResItem(); resItem.Path = fileInfo.Name; resItem.Md5 = MD5Util.Get(filePath); resItem.Size = fileInfo.Length; resPack.items.Add(resItem); } } resPack.packageType = fileType; if (fileType == FileType.Zip) { resPack.packageMd5 = MD5Util.Get(packagePath + "/" + resPack.id + ".zip"); resPack.packageSize = new FileInfo(packagePath + "/" + resPack.id + ".zip").Length; resPack.downloadPath = GetPackageStorePath() + "/" + resIndex.belong + "/" + resPack.id + ".zip"; } else { resPack.downloadPath = GetPackageStorePath() + "/" + resIndex.belong; } resPack.releasePath = releasePath; resIndex.packageDict.Add(resPack.id, resPack); } string json = JsonConvert.SerializeObject(resIndex, Formatting.Indented); FileUtil.SaveFileText(OutputPath, indexFileName + ".json", json); }
public static int GetHotfixVersion() { string vFile = HotfixDir + "/version.txt"; string str = FileUtil.ReadFileText(vFile); int ret = int.Parse(str); return(ret); }
private static void DownloadPackageFiles() { CleanPackageFiles(); Stopwatch sw = Stopwatch.StartNew(); FileUtil.CopyFolder(GetPackagePcRoot + "/" + Folder + "/PackageFiles", GetPackageFilesDir); Debug.LogWarning("复制PackageFiles文件时间:" + sw.ElapsedMilliseconds / 1000.0f + "ms"); }
private static void DownloadOriginalBundles() { CleanOriginalBundles(); Stopwatch sw = Stopwatch.StartNew(); FileUtil.CopyFolder(GetPackagePcRoot + "/" + Folder + "/OriginalBundles", AssetBundleHelper.GetOriginalBundlesPath(), ".manifest"); Debug.LogWarning("复制OriginalBundles文件时间:" + sw.ElapsedMilliseconds / 1000.0f + "ms"); }
private static void CreateAllDownloadJsonAndZip() { //压缩文件 string packagePath = PackageManager.OutputPath + ResPath.AllResources; if (Directory.Exists(packagePath)) { Directory.Delete(packagePath, true); } Directory.CreateDirectory(packagePath); string zipFileName = packagePath + "/" + ResPath.AllResources + ".zip"; string destDir = PackageManager.GetPackageDir() + "/" + ResPath.AllResources; string[] files = Directory.GetFiles(destDir, "*", SearchOption.AllDirectories); EditorUtility.DisplayProgressBar("压缩", "正在压缩文件(" + Path.GetFileName(packagePath), 1); List <string> pathInZipList = new List <string>(); for (int i = 0; i < files.Length; i++) { string str = Path.GetDirectoryName(files[i]); str = str.Replace("\\", "/"); str = str.Replace(PackageManager.GetPackageDir().Replace("\\", "/") + "/" + ResPath.AllResources + "/", ""); pathInZipList.Add(str + "/"); } ZipUtil.CreateZip(files, zipFileName, pathInZipList.ToArray(), 0); EditorUtility.ClearProgressBar(); //生成Index文件 ResIndex resIndex = new ResIndex(); resIndex.language = PackageManager.Language; resIndex.belong = ResPath.AllResources; resIndex.packageDict = new Dictionary <string, ResPack>(); ResPack resPack = new ResPack(); resPack.id = ResPath.AllResources; resPack.items = new List <ResItem>(); resPack.packageType = FileType.Zip; resPack.packageMd5 = MD5Util.Get(packagePath + "/" + resPack.id + ".zip"); resPack.packageSize = new FileInfo(packagePath + "/" + resPack.id + ".zip").Length; resPack.downloadPath = PackageManager.GetPackageStorePath() + "/" + resIndex.belong + "/" + resPack.id + ".zip"; resIndex.packageDict.Add(resPack.id, resPack); string json = JsonConvert.SerializeObject(resIndex, Formatting.Indented); FileUtil.SaveFileText(PackageManager.OutputPath, ResPath.AllResources + ".json", json); }
private static Dictionary <int, Dictionary <string, bool> > FindPhoneAudio() { DirectoryInfo dir = new DirectoryInfo(PhoneJsonPath); FileInfo[] files = dir.GetFiles("*.json"); Dictionary <int, Dictionary <string, bool> > fileDict = new Dictionary <int, Dictionary <string, bool> >(); foreach (var file in files) { string num = file.Name.Replace(".json", ""); int result; if (int.TryParse(num, out result) == false || result >= 20000) { continue; } string text = FileUtil.ReadFileText(file.FullName); SmsInfo info = JsonConvert.DeserializeObject <SmsInfo>(text); int npcId = -1; foreach (var talkInfo in info.smsTalkInfos) { if (talkInfo.NpcId != 0) { npcId = talkInfo.NpcId; } string mId = talkInfo.MusicID; if (string.IsNullOrEmpty(mId) || mId == "0") { continue; } if (fileDict.ContainsKey(npcId) == false) { fileDict[npcId] = new Dictionary <string, bool>(); } if (fileDict[npcId].ContainsKey(mId) == false) { fileDict[npcId].Add(mId, true); } } } string str = JsonConvert.SerializeObject(fileDict, Formatting.Indented); FileUtil.SaveFileText(GetPackageDir(), "PhoneAudio.json", str); return(fileDict); }
static void DownloadFirstRunBunlde() { Stopwatch sw = Stopwatch.StartNew(); CleanIndexFiles(); PublishRes.DeleteOuterStreamingAssets_AssetBundles(); Debug.LogWarning("删除文件时间:" + sw.ElapsedMilliseconds / 1000.0f + "ms"); sw.Restart(); FileUtil.CopyFolder(GetPackagePcRoot + "/" + Folder + "/StreamingAssets/AssetBundles", AssetBundleHelper.GetOuterStreamingAssetsPath() + "/AssetBundles"); Debug.LogWarning("复制OuterStreamingAssetsPath文件时间:" + sw.ElapsedMilliseconds / 1000.0f + "ms"); sw.Restart(); FileUtil.CopyFolder(GetPackagePcRoot + "/" + Folder + "/StreamingAssets/IndexFiles", AssetBundleHelper.GetOuterStreamingAssetsPath() + "/IndexFiles"); Debug.LogWarning("复制IndexFiles文件时间:" + sw.ElapsedMilliseconds / 1000.0f + "ms"); }
private static void CreateCoaxSleepAudioJson(string outPathRoot) { _sleepAudioJson = new List <CoaxSleepAudioJsonData>(); DirectoryInfo direction = new DirectoryInfo(outPathRoot); FileInfo[] files = direction.GetFiles("*", SearchOption.AllDirectories); foreach (var file in files) { string fullName = file.FullName.Replace("\\", "/"); fullName = Util.GetNoBreakingString(fullName); var data = new CoaxSleepAudioJsonData { AudioId = int.Parse(file.Name.Remove(file.Name.LastIndexOf(".", StringComparison.Ordinal))), MD5 = MD5Util.Get(file.FullName), Path = fullName.Split(new string[] { "CoaxSleepAudioFolder/" }, StringSplitOptions.RemoveEmptyEntries)[1], Size = file.Length, }; _sleepAudioJson.Add(data); } string path = Application.dataPath.Replace("Assets", "I18NData/zh-cn/CoaxSleepCache"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string jsonPath = path + "/coaxsleep.json"; if (File.Exists(jsonPath)) { File.Delete(jsonPath); } string json = JsonConvert.SerializeObject(_sleepAudioJson, Formatting.Indented); FileUtil.SaveFileText(path, "coaxsleep.json", json); CopyI18nData(false); }
static Dictionary <string, List <string> > FindAllStoryAudio() { DirectoryInfo dir = new DirectoryInfo(StoryJsonPath); FileInfo[] files = dir.GetFiles("*.json"); Dictionary <string, List <string> > fileDict = new Dictionary <string, List <string> >(); foreach (var file in files) { fileDict.Add(file.Name, new List <string>()); fileDict[file.Name].AddRange(GetStoryAudio(file.Name)); } string str = JsonConvert.SerializeObject(fileDict, Formatting.Indented); FileUtil.SaveFileText(GetPackageDir(), "StoryAudio.json", str); return(fileDict); }
private static List <string> GetStoryAudio(string eventId) { eventId = eventId.Replace(".json", ""); List <string> list = new List <string>(); FileInfo fileInfo = new FileInfo(StoryJsonPath + "/" + eventId + ".json"); if (fileInfo.Exists == false) { Debug.LogError("剧情json文件不存在=====ID:" + eventId); return(list); } string text = FileUtil.ReadFileText(fileInfo.FullName); List <DialogVo> dialogList = JsonConvert.DeserializeObject <List <DialogVo> >(text); foreach (var dialogVo in dialogList) { //处理剧情里的对话音频 if (string.IsNullOrEmpty(dialogVo.DubbingId) == false) { if (sharedAudioDict != null && sharedAudioDict.ContainsKey(dialogVo.DubbingId)) { continue; } list.Add(dialogVo.DubbingId); } if (dialogVo.Event != null) { list.AddRange(GetEventAudio(dialogVo.Event)); } } return(list); }
private static List <string> GetTelephoneAudio(string eventId) { eventId = eventId.Replace(".json", ""); List <string> list = new List <string>(); FileInfo fileInfo = new FileInfo(I18NDataPath + "/Telphone/" + eventId + ".json"); if (fileInfo.Exists == false) { Debug.LogError("手机json文件不存在=====ID:" + eventId); } else { string text = FileUtil.ReadFileText(fileInfo.FullName); TelephoneVo vo = JsonConvert.DeserializeObject <TelephoneVo>(text); foreach (var telephoneDialogVo in vo.dialogList) { if (string.IsNullOrEmpty(telephoneDialogVo.AudioId) == false) { if (sharedAudioDict != null && sharedAudioDict.ContainsKey(telephoneDialogVo.AudioId)) { continue; } list.Add(telephoneDialogVo.AudioId); } } if (vo.Event != null) { list.AddRange(GetEventAudio(vo.Event)); } } return(list); }
private static List <string> GetSmsAudio(string eventId) { eventId = eventId.Replace(".json", ""); List <string> list = new List <string>(); FileInfo fileInfo = new FileInfo(I18NDataPath + "/Sms/" + eventId + ".json"); if (fileInfo.Exists == false) { Debug.LogError("短信json文件不存在=====ID:" + eventId); } else { string text = FileUtil.ReadFileText(fileInfo.FullName); SmsVo vo = JsonConvert.DeserializeObject <SmsVo>(text); if (vo.Event != null) { list.AddRange(GetEventAudio(vo.Event)); } } return(list); }
private static void LoadIndexJson(string jsonPath, ref Dictionary <string, bool> fileDitc, bool exclude = false) { string str = FileUtil.ReadFileText(PackageManager.OutputPath + jsonPath + ".json"); if (string.IsNullOrEmpty(str)) { return; } ResIndex resIndex = JsonConvert.DeserializeObject <ResIndex>(str); int count = 0; foreach (var resPack in resIndex.packageDict) { string releasePath = resPack.Value.releasePath; foreach (var item in resPack.Value.items) { string key = releasePath + "/" + item.Path.ToLower(); if (exclude) { count++; fileDitc.Remove(key); } else if (fileDitc.ContainsKey(key) == false) { fileDitc.Add(key, true); } } } if (count > 0) { Debug.Log("<color='#660000>排除音频文件数量:" + count + "</color>"); } }
private static void CreateSpecial(ExcelWorksheet worksheet, string resId) { ResIndex resIndex = new ResIndex(); resIndex.packageDict = new Dictionary <string, ResPack>(); // 1内容 2筛选路径 3白名单 4黑名单 5ID var row = worksheet.Dimension.End.Row; List <BundleFilter> filterList = new List <BundleFilter>(); BundleFilter filter = null; for (int i = 2; i < row; i++) { object date = worksheet.Cells[i, 2].Value; if (date != null) { filter = new BundleFilter(); filterList.Add(filter); filter.DirPath = date.ToString().Replace("\\", "/"); string rootFolder = filter.DirPath; rootFolder = PackageManager.GetAssetBundleDir() + "/" + rootFolder; filter.BlackList = new BlackList(); filter.WhiteList = new WhiteList(); filter.BlackList.RootFolder = rootFolder; filter.WhiteList.RootFolder = rootFolder; AddToNameList(filter.WhiteList, worksheet.Cells[i, 3].Value); AddToNameList(filter.BlackList, worksheet.Cells[i, 4].Value); filter.Id = worksheet.Cells[i, 5].Value.ToString(); } else { AddToNameList(filter.WhiteList, worksheet.Cells[i, 3].Value); AddToNameList(filter.BlackList, worksheet.Cells[i, 4].Value); } } Dictionary <string, FileInfo> fileDict = new Dictionary <string, FileInfo>(); foreach (var bundleFilter in filterList) { List <FileInfo> files = bundleFilter.SearchFile(); foreach (var fileInfo in files) { string key = fileInfo.FullName.Replace("\\", "/"); if (!fileDict.ContainsKey(key)) { fileDict.Add(key, fileInfo); } } string releasePath = "AssetBundles/" + PackageManager.SystemTag; ResPack resPack = new ResPack(); resPack.id = bundleFilter.Id; resPack.downloadPath = PackageManager.GetPackageStorePath() + "/" + resId; resPack.releasePath = releasePath; resPack.items = new List <ResItem>(); resIndex.packageDict.Add(resPack.id, resPack); foreach (var fileInfo in fileDict) { ResItem resItem = new ResItem(); resItem.Path = GetRelatePath(fileInfo.Value.FullName); resItem.Md5 = MD5Util.Get(fileInfo.Key); resItem.Size = fileInfo.Value.Length; resPack.packageType = FileType.Original; resPack.items.Add(resItem); CopyFile(fileInfo.Value.FullName, PackageManager.OutputPath + resId + "/" + resItem.Path); } } string json = JsonConvert.SerializeObject(resIndex, Formatting.Indented); FileUtil.SaveFileText(PackageManager.OutputPath, resId + ".json", json); }
public static void CreateSingleZipAndJson(ExcelWorksheet worksheet, string resId) { ResIndex resIndex = new ResIndex(); // 1内容 2筛选路径 3白名单 4黑名单 var row = worksheet.Dimension.End.Row; List <BundleFilter> filterList = new List <BundleFilter>(); BundleFilter filter = null; for (int i = 2; i < row; i++) { object date = worksheet.Cells[i, 2].Value; if (date != null) { filter = new BundleFilter(); filterList.Add(filter); filter.DirPath = date.ToString(); string rootFolder = filter.DirPath; rootFolder = PackageManager.GetAssetBundleDir() + "/" + rootFolder; filter.BlackList = new BlackList(); filter.WhiteList = new WhiteList(); filter.BlackList.RootFolder = rootFolder; filter.WhiteList.RootFolder = rootFolder; AddToNameList(filter.WhiteList, worksheet.Cells[i, 3].Value); AddToNameList(filter.BlackList, worksheet.Cells[i, 4].Value); } else { AddToNameList(filter.WhiteList, worksheet.Cells[i, 3].Value); AddToNameList(filter.BlackList, worksheet.Cells[i, 4].Value); } } resIndex.belong = resId; resIndex.language = PackageManager.Language; resIndex.packageDict = new Dictionary <string, ResPack>(); Dictionary <string, FileInfo> fileDict = new Dictionary <string, FileInfo>(); if (resId == ResPath.AppStart) { //把共享音频放到AppStart里面下载 string root = PackageManager.GetAssetBundleDir(); foreach (var id in PackageManager.sharedAudioDict) { FileInfo fileInfo = new FileInfo(root + "/story/dubbing/" + id.Key + ".bytes"); string key = fileInfo.FullName.Replace("\\", "/"); fileDict.Add(key, fileInfo); } } foreach (var bundleFilter in filterList) { List <FileInfo> files = bundleFilter.SearchFile(); foreach (var fileInfo in files) { string key = fileInfo.FullName.Replace("\\", "/"); if (!fileDict.ContainsKey(key)) { fileDict.Add(key, fileInfo); } } } ResPack resPack = new ResPack(); resPack.id = resIndex.belong; resPack.releasePath = "AssetBundles/" + PackageManager.SystemTag; resPack.downloadPath = PackageManager.GetPackageStorePath() + "/" + resIndex.belong + "/" + resPack.id + ".zip"; resPack.items = new List <ResItem>(); resPack.packageType = FileType.Zip; resIndex.packageDict.Add(resPack.id, resPack); foreach (var fileInfo in fileDict) { ResItem resItem = new ResItem(); resItem.Path = GetRelatePath(fileInfo.Value.FullName); resItem.Md5 = MD5Util.Get(fileInfo.Key); resItem.Size = fileInfo.Value.Length; resPack.items.Add(resItem); } DeleteFile(resIndex); CopyFile(resIndex); string packagePath = PackageManager.OutputPath + resPack.id; if (Directory.Exists(packagePath)) { Directory.Delete(packagePath, true); } Directory.CreateDirectory(packagePath); string zipFileName = packagePath + "/" + resPack.id + ".zip"; string destDir = PackageManager.GetPackageDir() + "/" + resPack.id; string[] fileList = Directory.GetFiles(destDir, "*", SearchOption.AllDirectories); EditorUtility.DisplayProgressBar("压缩", "正在压缩文件(" + Path.GetFileName(packagePath), 1); List <string> pathInZipList = new List <string>(); for (int i = 0; i < fileList.Length; i++) { string str = Path.GetDirectoryName(fileList[i]); str = str.Replace("\\", "/"); str = str.Replace(PackageManager.GetPackageDir().Replace("\\", "/") + "/" + resPack.id + "/", ""); pathInZipList.Add(str + "/"); } ZipUtil.CreateZip(fileList, zipFileName, pathInZipList.ToArray(), 0); EditorUtility.ClearProgressBar(); resPack.packageMd5 = MD5Util.Get(zipFileName); resPack.packageSize = new FileInfo(zipFileName).Length; string json = JsonConvert.SerializeObject(resIndex, Formatting.Indented); FileUtil.SaveFileText(PackageManager.OutputPath, resId + ".json", json); }
public static void CreateMultiZipAndJson(ExcelWorksheet worksheet, string resId) { Stopwatch sw = Stopwatch.StartNew(); ResIndex resIndex = new ResIndex(); // 1内容 2筛选路径 3白名单 4黑名单 5ID var row = worksheet.Dimension.End.Row; List <BundleFilter> filterList = new List <BundleFilter>(); BundleFilter filter = null; for (int i = 2; i < row; i++) { object date = worksheet.Cells[i, 2].Value; if (date != null) { filter = new BundleFilter(); filterList.Add(filter); filter.DirPath = date.ToString().Replace("\\", "/"); string rootFolder = filter.DirPath; rootFolder = PackageManager.GetAssetBundleDir() + "/" + rootFolder; filter.BlackList = new BlackList(); filter.WhiteList = new WhiteList(); filter.BlackList.RootFolder = rootFolder; filter.WhiteList.RootFolder = rootFolder; AddToNameList(filter.WhiteList, worksheet.Cells[i, 3].Value); AddToNameList(filter.BlackList, worksheet.Cells[i, 4].Value); filter.Id = worksheet.Cells[i, 5].Value.ToString(); } else { AddToNameList(filter.WhiteList, worksheet.Cells[i, 3].Value); AddToNameList(filter.BlackList, worksheet.Cells[i, 4].Value); } } resIndex.belong = resId; resIndex.language = PackageManager.Language; resIndex.packageDict = new Dictionary <string, ResPack>(); Debug.Log("<color='#00ff00'>" + resId + "时间1->" + sw.ElapsedMilliseconds + "</color>"); DeleteFile(resIndex); Debug.Log("<color='#00ff00'>" + resId + "时间2.1->" + sw.ElapsedMilliseconds + "</color>"); string packagePath = PackageManager.OutputPath + resId; if (Directory.Exists(packagePath)) { Directory.Delete(packagePath, true); } Directory.CreateDirectory(packagePath); string releasePath = "AssetBundles/" + PackageManager.SystemTag; foreach (var bundleFilter in filterList) { List <FileInfo> files = bundleFilter.SearchFile(); ResPack resPack = new ResPack(); resPack.id = bundleFilter.Id; resPack.releasePath = releasePath; resPack.packageType = FileType.Zip; resPack.downloadPath = PackageManager.GetPackageStorePath() + "/" + resIndex.belong + "/" + resPack.id + ".zip"; resPack.items = new List <ResItem>(); resIndex.packageDict.Add(resPack.id, resPack); foreach (var fileInfo in files) { ResItem resItem = new ResItem(); resItem.Path = GetRelatePath(fileInfo.FullName); resItem.Md5 = MD5Util.Get(fileInfo.FullName); resItem.Size = fileInfo.Length; resPack.items.Add(resItem); CopyFile(fileInfo.FullName, PackageManager.GetPackageDir() + "/" + resId + "/" + resItem.Path); } } Debug.Log("<color='#00ff00'>" + resId + "时间2.2->" + sw.ElapsedMilliseconds + "</color>"); foreach (var resPack in resIndex.packageDict) { string zipFileName = packagePath + "/" + resPack.Value.id + ".zip"; List <string> fileList = new List <string>(); string rootPath = PackageManager.GetPackageDir().Replace("\\", "/") + "/" + resId + "/"; foreach (var item in resPack.Value.items) { fileList.Add(rootPath + item.Path); } EditorUtility.DisplayProgressBar("压缩", "正在压缩文件(" + Path.GetFileName(packagePath) + ")", 1); List <string> pathInZipList = new List <string>(); for (int i = 0; i < fileList.Count; i++) { string str = Path.GetDirectoryName(fileList[i]); str = str.Replace("\\", "/"); str = str.Replace( PackageManager.GetPackageDir().Replace("\\", "/") + "/" + resId + "/", ""); pathInZipList.Add(str + "/"); } ZipUtil.CreateZip(fileList.ToArray(), zipFileName, pathInZipList.ToArray(), 0); EditorUtility.ClearProgressBar(); resPack.Value.packageMd5 = MD5Util.Get(zipFileName); resPack.Value.packageSize = new FileInfo(zipFileName).Length; } Debug.Log("<color='#00ff00'>" + resId + "时间3->" + sw.ElapsedMilliseconds + "</color>"); string json = JsonConvert.SerializeObject(resIndex, Formatting.Indented); FileUtil.SaveFileText(PackageManager.OutputPath, resId + ".json", json); }
static void FindAdditionalI18NText() { //先创建一个中文的字典,然后创建一个HK的字典!最后对比K值 var _zhcnlanguageDict = new Dictionary <string, string>(); var _zhhklanguageDict = new Dictionary <string, string>(); char[] separator = new char[] { '=' }; string filePath1 = PathUtil.GetProjectRoot() + "I18NData/zh-cn/Languages/zh-CN.txt";//外部路径 string str1 = FileUtil.ReadFileText(filePath1); var strings = str1.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); int count = 0; foreach (var line in strings) { string trim = line.Trim(); if (string.IsNullOrEmpty(trim) || line.StartsWith("//")) { continue; } count++; string[] arr = trim.Split(separator, 2, StringSplitOptions.RemoveEmptyEntries); try { _zhcnlanguageDict.Add(arr[0].Trim(), Regex.Unescape(arr[1].Trim())); } catch (Exception e) { Debug.LogError("I18NManager lint:" + count + " " + e.Message); } } string filePath2 = PathUtil.GetProjectRoot() + "I18NData/zh-hk/Languages/zh-CN.txt";//外部路径 string str2 = FileUtil.ReadFileText(filePath2); var strings1 = str2.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); int count1 = 0; foreach (var line in strings1) { string trim = line.Trim(); if (string.IsNullOrEmpty(trim) || line.StartsWith("//")) { continue; } count1++; string[] arr = trim.Split(separator, 2, StringSplitOptions.RemoveEmptyEntries); try { _zhhklanguageDict.Add(arr[0].Trim(), Regex.Unescape(arr[1].Trim())); } catch (Exception e) { Debug.LogError("I18NManager lint:" + count + " " + e.Message); } } string logpath = PathUtil.GetProjectRoot() + "\\AdditionalI18Ntext.txt"; StreamWriter sw = new StreamWriter(logpath, true); List <string> additionalI18Ntext = new List <string>(); foreach (var v in _zhcnlanguageDict) { if (!_zhhklanguageDict.ContainsKey(v.Key)) { string trim = v.Value.Replace("\n", "\\n"); Debug.LogError(v.Key + "=" + trim); additionalI18Ntext.Add(v.Key + " = " + trim); //sw.WriteLine(v.Key + "=" + v.Value); } } foreach (var v in additionalI18Ntext) { sw.WriteLine(v); } sw.Flush(); sw.Close(); Debug.LogError("对比结束"); _zhcnlanguageDict.Clear(); _zhhklanguageDict.Clear(); }
static void ReplaceText() { // EditorUtility.DisplayProgressBar("提示", "开始加载CSV文件", 0f); string vFile = new DirectoryInfo(Application.dataPath).Parent.FullName + "/battle.csv"; string str = FileUtil.ReadFileText(vFile); var strings = str.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); Dictionary <string, List <string> > prefabsDict = new Dictionary <string, List <string> >(); int count = 0; foreach (var line in strings) { string trim = line.Trim(); if (string.IsNullOrEmpty(trim)) { continue; } string[] arr = trim.Split(new char[] { ',' }, 2, StringSplitOptions.RemoveEmptyEntries); string path = arr[0].Trim(); string[] separator = new[] { ".prefab:" }; arr = path.Split(separator, 2, StringSplitOptions.RemoveEmptyEntries); string prefab = arr[0] + ".prefab"; if (prefabsDict.ContainsKey(prefab) == false) { prefabsDict.Add(prefab, new List <string>()); } try { prefabsDict[prefab].Add(arr[1]); } catch (Exception e) { Console.WriteLine(e); throw; } count++; } // EditorUtility.DisplayProgressBar("提示", "替换Text (0/" + count + ")", 0.1f); count = 0; foreach (var dict in prefabsDict) { // if (count > 1) // break; GameObject prefab = AssetDatabase.LoadAssetAtPath <GameObject>(dict.Key); GameObject go = PrefabUtility.InstantiatePrefab(prefab) as GameObject; foreach (string textPath in dict.Value) { //去掉最后的数字 str = textPath.Substring(0, textPath.Length - 1); //去掉开头 int index = str.IndexOf("/", StringComparison.Ordinal); str = str.Substring(index + 1); int num; if (int.TryParse(str[str.Length - 1].ToString(), out num)) { str = str.Substring(0, str.Length - 1); } GameObject targetText; try { targetText = go.transform.Find(str).gameObject; } catch (Exception e) { Console.WriteLine(e); throw; } TextI18N textI18N = targetText.GetComponent <TextI18N>(); Text text = targetText.GetComponent <Text>(); if (text.GetType().Name.Contains("TextI18N")) { EditorUtility.DisplayDialog("Error!", dict.Key + "->" + str + "里面已经存在TextI18N", "Close"); return; } string childtext = text.text; Font childFont = text.font; FontStyle childFontStyle = text.fontStyle; int childFontSize = text.fontSize; float childSpacing = text.lineSpacing; bool childRichText = text.supportRichText; TextAnchor childAlignment = text.alignment; bool alignByGeometry = text.alignByGeometry; HorizontalWrapMode horizontalOverflow = text.horizontalOverflow; VerticalWrapMode verticalOverflow = text.verticalOverflow; bool resizeTextForBestFit = text.resizeTextForBestFit; Color color = text.color; Material material = text.material; bool raycastTarget = text.raycastTarget; DestroyImmediate(text); if (textI18N == null) { textI18N = targetText.AddComponent <TextI18N>(); } textI18N.TestString = childtext; textI18N.font = childFont; if (childFont.name == "lantingTeHei") { string[] bundles = AssetDatabase.GetAssetPathsFromAssetBundle("fonts/secondfont.bytes"); textI18N.CustomFont = AssetDatabase.LoadAssetAtPath <I18NFont>(bundles[0]); } else if (childFont.name == "huaWenYuanTi") { string[] bundles = AssetDatabase.GetAssetPathsFromAssetBundle("fonts/thirdfont.bytes"); textI18N.CustomFont = AssetDatabase.LoadAssetAtPath <I18NFont>(bundles[0]); } else { string[] bundles = AssetDatabase.GetAssetPathsFromAssetBundle("fonts/mainfont.bytes"); textI18N.CustomFont = AssetDatabase.LoadAssetAtPath <I18NFont>(bundles[0]); } textI18N.fontStyle = childFontStyle; textI18N.fontSize = childFontSize; textI18N.lineSpacing = childSpacing; textI18N.supportRichText = childRichText; textI18N.alignment = childAlignment; textI18N.alignByGeometry = alignByGeometry; textI18N.horizontalOverflow = horizontalOverflow; textI18N.verticalOverflow = verticalOverflow; textI18N.resizeTextForBestFit = resizeTextForBestFit; textI18N.color = color; textI18N.material = material; textI18N.raycastTarget = raycastTarget; } Debug.Log("<color='#CDEA11'>" + dict.Key + "</color>"); PrefabUtility.ReplacePrefab(go, prefab); DestroyImmediate(go); // count++; } EditorUtility.ClearProgressBar(); }
/// <summary> /// 找出剧情第4章以后的音频 /// </summary> static void CopyFile_StoryChapter(BlackList blackList) { Dictionary <string, List <string> > dict = FindAllStoryAudio(); Dictionary <string, List <string> > fileDict = new Dictionary <string, List <string> >(); int fileCount = 0; Dictionary <string, bool> includeDict = new Dictionary <string, bool>(); foreach (var json in dict) { if (json.Key.Contains("-")) { int result = 0; if (Int32.TryParse(json.Key[0].ToString(), out result)) { int result2 = 0; if (Int32.TryParse(json.Key.Substring(0, 2), out result2)) { if (CheckChapter(result2, blackList)) { if (!fileDict.ContainsKey(result2.ToString())) { fileDict.Add(result2.ToString(), new List <string>()); } fileDict[result2.ToString()].AddRange(json.Value); fileCount++; } else { AddToInclude(ref includeDict, json.Value); } } else { if (CheckChapter(result, blackList)) { if (!fileDict.ContainsKey(result.ToString())) { fileDict.Add(result.ToString(), new List <string>()); } fileDict[result.ToString()].AddRange(json.Value); fileCount++; } else { AddToInclude(ref includeDict, json.Value); } } } } } Debug.LogError("剧情json数量:" + fileCount); string destDir = GetPackageDir() + "/StoryAudio"; foreach (var file in fileDict) { DirectoryInfo dir = new DirectoryInfo(destDir + "/" + file.Key); if (dir.Exists == false) { dir.Create(); } int count = 0; foreach (var fileName in file.Value) { CopyDubbingFile(dir.FullName, fileName); EditorUtility.DisplayProgressBar("复制音频文件", "(" + count + "/" + file.Value.Count + ")" + dir.FullName, (float)count / file.Value.Count); } } EditorUtility.ClearProgressBar(); string packagePath = OutputPath + ModuleConfig.MODULE_MAIN_LINE; CreateZip(destDir, packagePath); GenerateIndexFile(destDir, Language, ModuleConfig.MODULE_MAIN_LINE, ResPath.MainStoryIndex, "story/dubbing", packagePath); //创建包含文件索引 ResIndex resIndex = new ResIndex(); resIndex.language = Language; resIndex.packageDict = new Dictionary <string, ResPack>(); resIndex.belong = "IncludeFiles"; ResPack resPack = new ResPack(); resPack.id = "story0-story1"; resPack.releasePath = "AssetBundles/" + SystemTag + "/story/dubbing"; resPack.items = new List <ResItem>(); resIndex.packageDict.Add("IncludePack", resPack); foreach (var include in includeDict) { ResItem item = new ResItem(); item.Path = include.Key + ".bytes"; resPack.items.Add(item); } string str = JsonConvert.SerializeObject(resIndex, Formatting.Indented); FileUtil.SaveFileText(OutputPath, ResPath.IncludeIndex + ".json", str); }
static void CopyFile_AllAudio(BlackList blackList) { Stopwatch sw = Stopwatch.StartNew(); string dir1 = GetPackageDir() + "/LoveStoryAudio"; string dir2 = GetPackageDir() + "/StoryAudio"; string dir3 = GetPackageDir() + "/PhoneAudio"; string destDir = GetPackageDir() + "/AllAudio"; if (Directory.Exists(destDir)) { Directory.Delete(destDir, true); } Directory.CreateDirectory(destDir); string[] files = Directory.GetFiles(dir1, "*", SearchOption.AllDirectories); CopyFile(files, destDir + "/story/dubbing"); files = Directory.GetFiles(dir2, "*", SearchOption.AllDirectories); CopyFile(files, destDir + "/story/dubbing"); files = Directory.GetFiles(dir3, "*", SearchOption.AllDirectories); CopyFile(files, destDir + "/music/phonedialogs"); //压缩文件 string packagePath = OutputPath + "AllAudio"; if (Directory.Exists(packagePath)) { Directory.Delete(packagePath, true); } Directory.CreateDirectory(packagePath); string zipFileName = packagePath + "/AllAudio.zip"; files = Directory.GetFiles(destDir, "*", SearchOption.AllDirectories); EditorUtility.DisplayProgressBar("压缩", "正在压缩文件(" + Path.GetFileName(packagePath), 1); List <string> pathInZipList = new List <string>(); for (int i = 0; i < files.Length; i++) { string str = Path.GetDirectoryName(files[i]); str = str.Replace("\\", "/"); str = str.Replace(GetPackageDir().Replace("\\", "/") + "/AllAudio/", ""); pathInZipList.Add(str + "/"); } ZipUtil.CreateZip(files, zipFileName, pathInZipList.ToArray(), 0); EditorUtility.ClearProgressBar(); //生成Index文件 string releasePath = "AssetBundles/" + SystemTag + "/"; ResIndex resIndex = new ResIndex(); resIndex.language = Language; resIndex.belong = "AllAudio"; resIndex.packageDict = new Dictionary <string, ResPack>(); files = Directory.GetFiles(destDir, "*", SearchOption.AllDirectories); ResPack resPack = new ResPack(); resPack.id = "AllAudio"; resPack.items = new List <ResItem>(); resPack.packageType = FileType.Zip; resPack.packageMd5 = MD5Util.Get(packagePath + "/" + resPack.id + ".zip"); resPack.packageSize = new FileInfo(packagePath + "/" + resPack.id + ".zip").Length; resPack.downloadPath = GetPackageStorePath() + "/" + resIndex.belong + "/" + resPack.id + ".zip"; resPack.releasePath = releasePath; resIndex.packageDict.Add(resPack.id, resPack); string json = JsonConvert.SerializeObject(resIndex, Formatting.Indented); FileUtil.SaveFileText(OutputPath, ResPath.AllAudioIndex + ".json", json); Debug.Log("<color='#00ff66'>CopyFile_AllAudio耗时:" + sw.ElapsedMilliseconds / 1000.0f + "</color>"); }
static Dictionary <string, List <string> > FindLoveStoryAudio() { DirectoryInfo dir = new DirectoryInfo(Application.persistentDataPath + "/DataCache/appointment_c"); if (dir.Exists == false) { Debug.LogError("appointment_c文件夹不存在!"); return(null); } FileInfo[] files = dir.GetFiles("*"); FileInfo targetFile = null; foreach (FileInfo file in files) { if (file.Name.ToLower().StartsWith("rules")) { targetFile = file; break; } } if (targetFile == null) { Debug.LogError("appointment_c/rules文件不存在!"); return(null); } Dictionary <string, List <string> > fileDict = new Dictionary <string, List <string> >(); EditorUtility.DisplayProgressBar("查找LoveStory音频", "", 0); byte[] dataFile = FileUtil.GetBytesFile(targetFile.DirectoryName, targetFile.Name); MemoryStream m = new MemoryStream(dataFile); MessageParser <AppointmentRuleRes> parser = new MessageParser <AppointmentRuleRes>(() => new AppointmentRuleRes()); AppointmentRuleRes res = parser.ParseFrom(m); int count = 0; foreach (var rule in res.AppointmentRules) { count++; string cardId = rule.ActiveCards[0].ToString(); fileDict.Add(cardId, new List <string>()); foreach (var pb in rule.GateInfos) { fileDict[cardId].AddRange(GetStoryAudio(pb.SceneId)); } EditorUtility.DisplayProgressBar("查找LoveStory音频", "cardId:" + cardId + "(" + count + "/" + res.AppointmentRules.Count + ")", (float)count / res.AppointmentRules.Count); } string str = JsonConvert.SerializeObject(fileDict, Formatting.Indented); FileUtil.SaveFileText(GetPackageDir(), "LoveStoryAudio.json", str); EditorUtility.ClearProgressBar(); return(fileDict); }
static Dictionary <string, List <string> > FindVisitStoryAudio() { DirectoryInfo dir = new DirectoryInfo(Application.persistentDataPath + "/DataCache/visiting_c"); if (dir.Exists == false) { Debug.LogError("visiting_c文件夹不存在!"); return(null); } FileInfo[] files = dir.GetFiles("*"); FileInfo targetFile = null; foreach (FileInfo file in files) { if (file.Name.ToLower().StartsWith("rules")) { targetFile = file; break; } } if (targetFile == null) { Debug.LogError("visiting_c/rules文件不存在!"); return(null); } Dictionary <string, List <string> > fileDict = new Dictionary <string, List <string> >(); EditorUtility.DisplayProgressBar("查找VisitStory音频", "", 0); byte[] dataFile = FileUtil.GetBytesFile(targetFile.DirectoryName, targetFile.Name); MemoryStream m = new MemoryStream(dataFile); MessageParser <VisitingRuleRes> parser = new MessageParser <VisitingRuleRes>(() => new VisitingRuleRes()); VisitingRuleRes res = parser.ParseFrom(m); int count = 0; foreach (var rule in res.LevelRules) { count++; if (rule.Type == LevelTypePB.Story) { string playerId = ((int)rule.Player) + ""; if (fileDict.ContainsKey(playerId) == false) { fileDict.Add(playerId, new List <string>()); } fileDict[playerId].AddRange(GetStoryAudio(rule.LevelMark)); EditorUtility.DisplayProgressBar("查找VisitStory音频", "playerId:" + playerId + "(" + count + ")", 1); } } string str = JsonConvert.SerializeObject(fileDict, Formatting.Indented); FileUtil.SaveFileText(GetPackageDir(), "VisitStoryAudio.json", str); EditorUtility.ClearProgressBar(); return(fileDict); }