private void CheckFiles(string filteredStr) { System.Action <string, int, int> updateProgress = (text, now, max) => { EditorUtility.DisplayProgressBar("Check", text, (float)now / (float)max); }; m_FilteredPathList.Clear(); string[] guids = AssetDatabase.FindAssets(filteredStr); int length = guids.Length; for (int i = 0; i < length; i++) { string guid = guids[i]; string path = AssetDatabase.GUIDToAssetPath(guid); string fullPath = Path.Combine(System.Environment.CurrentDirectory, path); string text = System.IO.File.ReadAllText(fullPath); if (!string.IsNullOrEmpty(text)) { if (fullPath.EndsWith("prefab") || fullPath.EndsWith("unity")) { if (JpUtil.PlainText_IsContainsJapanese(text)) { m_FilteredPathList.Add(AssetDatabase.GUIDToAssetPath(guid)); continue; } } else //text or script { //clear the comment lines text = JpUtil.CleanCommentLines(text); if (JpUtil.IsContainsJapanese(text)) { m_FilteredPathList.Add(AssetDatabase.GUIDToAssetPath(guid)); } } } updateProgress(path, (i + 1), length); } //UnityEditor.UI.LocalizationTextEditor.ClearConsole(); Debug.LogFormat("Total :<color=white>{0}</color> files", m_FilteredPathList.Count); EditorUtility.ClearProgressBar(); }
/// <summary> /// 统计需要本地化的行数 /// </summary> /// <param name="filteredStr"></param> private void CalculateFileLines(string filteredStr) { long lineCount = 0; m_FilteredPathList.Clear(); string[] guids = AssetDatabase.FindAssets(filteredStr); foreach (var guid in guids) { string path = AssetDatabase.GUIDToAssetPath(guid); if (true) { string fullPath = Path.Combine(System.Environment.CurrentDirectory, path); string text = System.IO.File.ReadAllText(fullPath); if (!string.IsNullOrEmpty(text)) { if (fullPath.EndsWith("prefab") || fullPath.EndsWith("unity")) { foreach (var line in text.Split('\n')) { if (JpUtil.PlainText_IsContainsJapanese(line)) { lineCount++; } } } else //text or script { //clear the comment lines text = JpUtil.CleanCommentLines(text); foreach (var line in text.Split('\n')) { if (JpUtil.IsContainsJapanese(line)) { lineCount++; } } } } } } //UnityEditor.UI.LocalizationTextEditor.ClearConsole(); Debug.LogFormat("Total :<color=white>{0}</color> lines", lineCount); }
public static void UpgradeToLocalizationText(string assetPath, string textCompGUID, string textCompFileID, string localizeCompGUID, string localizeCompFileID, List <string> jpTextList) { ClearConsole(); string formatedGUID = string.Format("guid: {0},", localizeCompGUID); string fullPath = Path.Combine(Application.dataPath.Substring(0, Application.dataPath.LastIndexOf('/')), assetPath); string[] lines = System.IO.File.ReadAllLines(fullPath); string fullText = System.IO.File.ReadAllText(fullPath); for (int i = 0; i < lines.Length; i++) { if (lines[i].Contains(textCompFileID)) { int scriptLineIdx = i; //往下遍历直到找到m_Text while (i < lines.Length) { if (lines[i].Contains("--- !u!")) //发现下一个控件时跳出 { break; } if (JpUtil.PlainText_IsContainsJapanese(lines[i])) { string jpText = Regex.Unescape(lines[i].Split('\"')[1]).Replace("\n", "\\n"); jpTextList.Add(jpText); //发现了FileID相同 但GUID不同的情况,所以直接把FileID后面的GUID替换 lines[scriptLineIdx] = Regex.Replace(lines[scriptLineIdx], guidReplacePattern, formatedGUID); lines[scriptLineIdx] = lines[scriptLineIdx].Replace(textCompFileID, localizeCompFileID); break; } i++; } } } string text = string.Join("\n", lines); System.IO.File.WriteAllText(fullPath, text); AssetDatabase.Refresh(); }