using Boo.Lang; using DG.Tweening.Plugins.Core.PathCore; using ICSharpCode.SharpZipLib.Core; using System; using System.IO; using System.Text; using System.Text.RegularExpressions; using UnityEditor; using UnityEngine; namespace GameEditor.Core { public class FindLanguageIdTool { static string luaPath = Application.dataPath + "\\ManagedResources\\~Lua"; static List FileList = new List(); static List PathList = new List(); static List GetAllFileInfo(DirectoryInfo dir) { FileInfo[] allFile = dir.GetFiles(); foreach (FileInfo file in allFile) { if (file.Name.EndsWith(".meta")) { continue; } PathList.Add(file.FullName); } DirectoryInfo[] allDir = dir.GetDirectories(); foreach (DirectoryInfo d in allDir) { GetAllFileInfo(d); } return PathList; } [MenuItem("Tools/查找LanguageID")] public static void Find() { Debug.Log("开始"); GetAllFileInfo(new DirectoryInfo(luaPath)); foreach (string path in PathList) { if (File.Exists(path)) { string[] strs = File.ReadAllLines(path, Encoding.Default); //依次读取每行数据 foreach (string s in strs) { string splicStr1 = "GetLanguageStrById("; string splicStr2 = "ShowTipByLanguageId("; SplitString(s, splicStr1); SplitString(s, splicStr2); } } } WriteTxt(); } //拆分字符串 public static void SplitString(string str, string splicStr) { int index = str.IndexOf(splicStr); if (index > -1 && str.Length > 0) { string s1 = str.Substring(index + splicStr.Length); int end = s1.IndexOf(")"); string s2 = s1.Substring(0, end); if (IsPureNum(s2)) { bool state = true; for(int i = 0; i < FileList.Count; i++) { if (FileList[i] == s2) { state = false; break; } } if (state) { FileList.Add(s2); } SplitString(s1, splicStr); } } } //判断字符串是否为数字 public static bool IsPureNum(string str) { if (str.Length == 0 || str == null)//验证这个字符串是否为空 { return false; } byte[] strBytes = Encoding.ASCII.GetBytes(str);//获取字符串的byte类型的字符数组,编码方式ASCII foreach (byte strByte in strBytes) { if ((strByte < 48) || (strByte > 57))//判断每个字符是否为数字,根据每个字符的ASCII值所在范围判断 { return false;//不是,就返回false } } return true;//是,就返回true } public static void WriteTxt() { Debug.Log("写入中"); string txtPath = Application.dataPath + "\\LanguageID.txt"; string[] str = FileList.ToArray(); // 判断文件是否存在,不存在则创建,否则清空重新写入 if (!File.Exists(txtPath)) { FileStream fs = new FileStream(txtPath, FileMode.Append); StreamWriter sw = new StreamWriter(fs); for (int v = 0; v < FileList.Count; v++) { sw.WriteLine(FileList[v]); } sw.Close(); } else { File.WriteAllText(txtPath, string.Empty); File.WriteAllLines(txtPath, str); } Debug.Log("写入结束"); Debug.Log("路径:" + txtPath); } } }