From 00da1e59dbf5182aae5e201dc5318a9be50b02c6 Mon Sep 17 00:00:00 2001 From: client_Wu Xijin <364452445@qq.com> Date: 星期一, 15 四月 2019 16:22:15 +0800 Subject: [PATCH] 6519 【工具】【2.0】删除无用KYE的工具 --- Assets/Editor/Tool/UIAssetCheck.cs | 307 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 307 insertions(+), 0 deletions(-) diff --git a/Assets/Editor/Tool/UIAssetCheck.cs b/Assets/Editor/Tool/UIAssetCheck.cs index f54ad57..db93e84 100644 --- a/Assets/Editor/Tool/UIAssetCheck.cs +++ b/Assets/Editor/Tool/UIAssetCheck.cs @@ -366,4 +366,311 @@ } +public class RemoveUnUsedIconKey +{ + static List<string> ignoreKeyList = new List<string>() + { + "Remark_","GemTypeMini_","AllianceBossRank_","GemTypeMini_","RealmSelectBottom_","XT_TJ_","Fb_", + "MultipleExp_Icon_","MapNPC_Colour_","LocalMapTaskState_","EquipDefaultIcon_" + }; + + static int taskCount = 1; + static int completedTaskCount = 0; + static Dictionary<string, string> iconKeyMap = new Dictionary<string, string>(); + + static List<Column> iconKeyRefrences = new List<Column>(); + static List<string> csharpFileContents = new List<string>(); + static List<string> usedIconKeys = new List<string>(); + static List<AnalyzeTask> tasks = new List<AnalyzeTask>(); + + [MenuItem("绋嬪簭/UI Assets/绉婚櫎鏃犵敤鐨処conKey")] + public static void Remove() + { + tasks.Clear(); + var iconKeys = GetOriginalIconKeys(); + + taskCount = iconKeys.Count; + completedTaskCount = 0; + + var count = 0; + var task = new AnalyzeTask(); + tasks.Add(task); + foreach (var key in iconKeys) + { + task.Add(new IconKeyInfo() + { + key = key, + unused = false + }); + + if (count >= 200) + { + count = 0; + task = new AnalyzeTask(); + tasks.Add(task); + } + count++; + } + + iconKeyMap = GetIconKeyMap(); + iconKeyRefrences = GetAllIconKeyRefrences(); + csharpFileContents = GetAllCSharpFileContents(); + + try + { + EditorApplication.update += OnUpdate; + Analyze(); + } + catch (Exception e) + { + EditorUtility.ClearProgressBar(); + EditorApplication.update -= OnUpdate; + Debug.Log(e); + } + + } + + static void Analyze() + { + foreach (var task in tasks) + { + ThreadPool.QueueUserWorkItem(x => + { + for (int i = task.iconKeys.Count - 1; i >= 0; i--) + { + task.completed++; + var info = task.iconKeys[i]; + if (ContainByTables(info.key, ref iconKeyRefrences)) + { + //Debug.LogFormat("鎵惧埌涓�涓鍏朵粬閰嶇疆閰嶄欢寮曠敤鐨� icon key锛歿0}", info.key); + continue; + } + + if (ContainByCSharpFile(info.key, ref csharpFileContents)) + { + // Debug.LogFormat("鎵惧埌涓�涓啓鍦–#鏂囦欢涓殑 icon key锛歿0}", info.key); + continue; + } + + info.unused = true; + task.iconKeys[i] = info; + } + + task.done = true; + }); + } + } + + static void ProcessUnUsedIconKeys() + { + var lines = new List<string>(File.ReadAllLines(Application.dataPath + "/ResourcesOut/Refdata/Config/Icon.txt")); + var unUsedIconKeys = new List<string>(); + foreach (var task in tasks) + { + foreach (var iconkey in task.iconKeys) + { + if (iconkey.unused) + { + unUsedIconKeys.Add(iconkey.key); + } + } + } + + for (int i = lines.Count - 1; i >= 3; i--) + { + var contents = lines[i].Split('\t'); + if (!contents.IsNullOrEmpty()) + { + if (unUsedIconKeys.Contains(contents[0])) + { + lines.RemoveAt(i); + } + } + } + + File.WriteAllLines(Application.dataPath + "/ResourcesOut/Refdata/Config/Icon.txt", lines.ToArray()); + } + + static Dictionary<string, string> GetIconKeyMap() + { + var lines = File.ReadAllLines(Application.dataPath + "/Editor/Config/TxtIconKeys.txt"); + var map = new Dictionary<string, string>(); + + for (int i = 1; i < lines.Length; i++) + { + var line = lines[i]; + var contents = line.Split('\t'); + if (!contents.IsNullOrEmpty() && contents.Length >= 2) + { + map[contents[0]] = contents[1]; + } + } + + return map; + } + + static List<string> GetOriginalIconKeys() + { + var lines = File.ReadAllLines(Application.dataPath + "/ResourcesOut/Refdata/Config/Icon.txt"); + var iconKeys = new List<string>(); + for (int i = 3; i < lines.Length; i++) + { + var contents = lines[i].Split('\t'); + if (!contents.IsNullOrEmpty()) + { + iconKeys.Add(contents[0]); + } + } + + return iconKeys; + } + + static List<Column> GetAllIconKeyRefrences() + { + var files = FileExtersion.GetFileInfos(Application.dataPath + "/ResourcesOut/Refdata/Config", new string[] { "*.txt", "*.TXT" }); + + var columns = new List<Column>(); + foreach (var file in files) + { + var nameWithoutExtension = Path.GetFileNameWithoutExtension(file.FullName); + if (!iconKeyMap.ContainsKey(nameWithoutExtension)) + { + continue; + } + + var iconKeyField = iconKeyMap[nameWithoutExtension]; + var lines = File.ReadAllLines(file.FullName); + var fields = new List<string>(lines[1].Split('\t')); + var index = fields.IndexOf(iconKeyField); + + if (index == -1) + { + continue; + } + + var column = new Column() + { + name = fields[index], + values = new List<string>() + }; + + columns.Add(column); + for (int i = 1; i < lines.Length; i++) + { + var line = lines[i]; + var contents = line.Split('\t'); + column.values.Add(contents[index]); + } + } + + return columns; + } + + static List<string> GetAllCSharpFileContents() + { + var files = FileExtersion.GetFileInfos(Application.dataPath + "/Scripts", new string[] { "*.cs" }); + var contents = new List<string>(); + + foreach (var file in files) + { + contents.Add(File.ReadAllText(file.FullName)); + } + + return contents; + } + + static bool ContainByTables(string key, ref List<Column> columns) + { + foreach (var column in columns) + { + foreach (var value in column.values) + { + if (key == value) + { + return true; + } + } + } + + return false; + } + + static bool ContainByCSharpFile(string key, ref List<string> csharpContents) + { + foreach (var ignore in ignoreKeyList) + { + if (Regex.IsMatch(key, ignore)) + { + return true; + } + } + + var pattern = string.Format(@"\.SetSprite.*{0}.*\);", key); + foreach (var content in csharpContents) + { + if (Regex.IsMatch(content, pattern)) + { + return true; + } + } + + return false; + } + + static void OnUpdate() + { + var done = true; + completedTaskCount = 0; + foreach (var task in tasks) + { + completedTaskCount += task.completed; + if (!task.done) + { + done = false; + } + } + + EditorUtility.DisplayProgressBar("鍒嗘瀽鏃犵敤IconKey", + string.Format("姝e湪鍒嗘瀽绗瑊0}涓狪conKey,鍏辫{1}涓�", completedTaskCount + 1, taskCount), + (float)completedTaskCount / taskCount); + + if (done) + { + EditorUtility.ClearProgressBar(); + ProcessUnUsedIconKeys(); + EditorApplication.update -= OnUpdate; + } + } + + struct Column + { + public string name; + public List<string> values; + } + + struct IconKeyInfo + { + public string key; + public bool unused; + } + + class AnalyzeTask + { + public int total; + public int completed; + public bool done; + public List<IconKeyInfo> iconKeys; + + public AnalyzeTask() + { + iconKeys = new List<IconKeyInfo>(); + } + + public void Add(IconKeyInfo key) + { + iconKeys.Add(key); + } + } + +} -- Gitblit v1.8.0