| | |
| | | { |
| | | 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("正在删除第{0}张图片,共{1}张", count + 1, total), (float)count / total); |
| | | count++; |
| | | AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(sprite.guid)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | EditorUtility.ClearProgressBar(); |
| | | } |
| | | |
| | | static bool ContainByIconTable(SpriteInfo info) |
| | |
| | | |
| | | 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/移除无用的IconKey")] |
| | |
| | | iconKeyMap = GetIconKeyMap(); |
| | | iconKeyRefrences = GetAllIconKeyRefrences(); |
| | | csharpFileContents = GetAllCSharpFileContents(); |
| | | generalContent = GetGeneralContent(); |
| | | prefabTexts = GetPrefabTexts(); |
| | | |
| | | try |
| | | { |
| | |
| | | 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("找到一个写在C#文件中的 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; |
| | | } |
| | | |
| | |
| | | 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)); |
| | | } |
| | | } |
| | | |
| | |
| | | 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; |
| | |
| | | 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; |
| | | } |
| | |
| | | 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; |