From 9c740bd70218eefe8e9a4a7fd8ef5d88e0557a32 Mon Sep 17 00:00:00 2001
From: client_Wu Xijin <364452445@qq.com>
Date: 星期二, 16 四月 2019 11:47:56 +0800
Subject: [PATCH] 6519  【工具】【2.0】删除无用KYE的工具

---
 Assets/Editor/Tool/UIAssetCheck.cs |  158 ++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 127 insertions(+), 31 deletions(-)

diff --git a/Assets/Editor/Tool/UIAssetCheck.cs b/Assets/Editor/Tool/UIAssetCheck.cs
index db93e84..1f1d878 100644
--- a/Assets/Editor/Tool/UIAssetCheck.cs
+++ b/Assets/Editor/Tool/UIAssetCheck.cs
@@ -240,14 +240,27 @@
             {
                 if (sprite.unUsed)
                 {
-                    AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(sprite.guid));
                     Debug.LogFormat("鎵惧埌涓�寮犳棤鐢ㄧ殑鍥剧墖锛氭枃浠跺す->{0};鍥剧墖鍚嶇О->{1}", sprite.folder, sprite.name);
                     total++;
                 }
             }
         }
 
-        Debug.LogFormat("绱鎵惧埌{0}寮犳棤鐢ㄥ浘鐗�", total);
+        var count = 0;
+        foreach (var task in tasks)
+        {
+            foreach (var sprite in task.sprites)
+            {
+                if (sprite.unUsed)
+                {
+                    EditorUtility.DisplayProgressBar("鍒犻櫎Sprite", string.Format("姝e湪鍒犻櫎绗瑊0}寮犲浘鐗囷紝鍏眥1}寮�", count + 1, total), (float)count / total);
+                    count++;
+                    AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(sprite.guid));
+                }
+            }
+        }
+
+        EditorUtility.ClearProgressBar();
     }
 
     static bool ContainByIconTable(SpriteInfo info)
@@ -368,19 +381,24 @@
 
 public class RemoveUnUsedIconKey
 {
+    static string uiroot1 = "Assets/ResourcesOut/UI/Window";
+    static string uiroot2 = "Assets/ResourcesOut/UI/PriorityWindow";
+    static string uiroot3 = "Assets/ResourcesOut/UI/Prefab";
+
     static List<string> ignoreKeyList = new List<string>()
     {
         "Remark_","GemTypeMini_","AllianceBossRank_","GemTypeMini_","RealmSelectBottom_","XT_TJ_","Fb_",
-        "MultipleExp_Icon_","MapNPC_Colour_","LocalMapTaskState_","EquipDefaultIcon_"
+        "MultipleExp_Icon_","MapNPC_Colour_","LocalMapTaskState_","EquipDefaultIcon_","OpenServerActivty_"
     };
 
     static int taskCount = 1;
     static int completedTaskCount = 0;
-    static Dictionary<string, string> iconKeyMap = new Dictionary<string, string>();
+    static Dictionary<string, List<string>> iconKeyMap = new Dictionary<string, List<string>>();
 
+    static List<string> prefabTexts = new List<string>();
     static List<Column> iconKeyRefrences = new List<Column>();
     static List<string> csharpFileContents = new List<string>();
-    static List<string> usedIconKeys = new List<string>();
+    static string generalContent = string.Empty;
     static List<AnalyzeTask> tasks = new List<AnalyzeTask>();
 
     [MenuItem("绋嬪簭/UI Assets/绉婚櫎鏃犵敤鐨処conKey")]
@@ -415,6 +433,8 @@
         iconKeyMap = GetIconKeyMap();
         iconKeyRefrences = GetAllIconKeyRefrences();
         csharpFileContents = GetAllCSharpFileContents();
+        generalContent = GetGeneralContent();
+        prefabTexts = GetPrefabTexts();
 
         try
         {
@@ -442,13 +462,25 @@
                     var info = task.iconKeys[i];
                     if (ContainByTables(info.key, ref iconKeyRefrences))
                     {
-                        //Debug.LogFormat("鎵惧埌涓�涓鍏朵粬閰嶇疆閰嶄欢寮曠敤鐨� icon key锛歿0}", info.key);
+                        // Debug.LogFormat("鎵惧埌涓�涓鍏朵粬閰嶇疆閰嶄欢寮曠敤鐨� icon key锛歿0}", info.key);
                         continue;
                     }
 
                     if (ContainByCSharpFile(info.key, ref csharpFileContents))
                     {
                         // Debug.LogFormat("鎵惧埌涓�涓啓鍦–#鏂囦欢涓殑 icon key锛歿0}", info.key);
+                        continue;
+                    }
+
+                    if (ContainByGeneralConfig(info.key, ref generalContent))
+                    {
+                        // Debug.LogFormat("鎵惧埌涓�涓啓鍦ㄥ姛鑳介厤缃〃涓殑 icon key锛歿0}", info.key);
+                        continue;
+                    }
+
+                    if (ContainByPrefab(info.key, ref prefabTexts))
+                    {
+                        //Debug.LogFormat("鎵惧埌涓�涓prefab渚濊禆鐨� icon key锛歿0}", info.key);
                         continue;
                     }
 
@@ -491,18 +523,19 @@
         File.WriteAllLines(Application.dataPath + "/ResourcesOut/Refdata/Config/Icon.txt", lines.ToArray());
     }
 
-    static Dictionary<string, string> GetIconKeyMap()
+    static Dictionary<string, List<string>> GetIconKeyMap()
     {
         var lines = File.ReadAllLines(Application.dataPath + "/Editor/Config/TxtIconKeys.txt");
-        var map = new Dictionary<string, string>();
+        var map = new Dictionary<string, List<string>>();
 
         for (int i = 1; i < lines.Length; i++)
         {
             var line = lines[i];
-            var contents = line.Split('\t');
-            if (!contents.IsNullOrEmpty() && contents.Length >= 2)
+            var contents = new List<string>(line.Split('\t'));
+            if (!contents.IsNullOrEmpty() && contents.Count >= 2)
             {
-                map[contents[0]] = contents[1];
+                var fields = map[contents[0]] = new List<string>();
+                fields.AddRange(contents.GetRange(1, contents.Count - 1));
             }
         }
 
@@ -538,29 +571,47 @@
                 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)
+            var fields0 = new List<string>(lines[0].Split('\t'));
+            var fields1 = new List<string>(lines[1].Split('\t'));
+            var refrences = iconKeyMap[nameWithoutExtension];
+            foreach (var refrence in refrences)
             {
-                continue;
+                var name = string.Empty;
+                var index = fields0.IndexOf(refrence);
+                if (index != -1)
+                {
+                    name = fields0[index];
+                }
+                else
+                {
+                    index = fields1.IndexOf(refrence);
+                    if (index != -1)
+                    {
+                        name = fields1[index];
+                    }
+                }
+
+                if (index == -1)
+                {
+                    continue;
+                }
+
+                var column = new Column()
+                {
+                    name = name,
+                    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]);
+                }
             }
 
-            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;
@@ -579,13 +630,40 @@
         return contents;
     }
 
+    static List<string> GetPrefabTexts()
+    {
+        var guids = new List<string>();
+        guids.AddRange(AssetDatabase.FindAssets("t:prefab", new string[] { uiroot1 }));
+        guids.AddRange(AssetDatabase.FindAssets("t:prefab", new string[] { uiroot2 }));
+        guids.AddRange(AssetDatabase.FindAssets("t:prefab", new string[] { uiroot3 }));
+
+        var assetPaths = new List<string>();
+        foreach (var item in guids)
+        {
+            assetPaths.Add(AssetDatabase.GUIDToAssetPath(item));
+        }
+
+        prefabTexts = new List<string>();
+        foreach (var path in assetPaths)
+        {
+            prefabTexts.Add(File.ReadAllText(Application.dataPath + path.Substring(6, path.Length - 6)));
+        }
+
+        return prefabTexts;
+    }
+
+    static string GetGeneralContent()
+    {
+        return File.ReadAllText(Application.dataPath + "/ResourcesOut/Refdata/Config/FuncConfig.txt");
+    }
+
     static bool ContainByTables(string key, ref List<Column> columns)
     {
         foreach (var column in columns)
         {
             foreach (var value in column.values)
             {
-                if (key == value)
+                if (Regex.IsMatch(value, key))
                 {
                     return true;
                 }
@@ -617,6 +695,24 @@
         return false;
     }
 
+    static bool ContainByGeneralConfig(string key, ref string content)
+    {
+        return Regex.IsMatch(content, key);
+    }
+
+    static bool ContainByPrefab(string key, ref List<string> prefabTexts)
+    {
+        foreach (var text in prefabTexts)
+        {
+            if (Regex.IsMatch(text, key))
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     static void OnUpdate()
     {
         var done = true;

--
Gitblit v1.8.0