public static void ScanAllSprite() { // 1.找到所有的UI图片的meta文件 // 2.读取meta文件中的Guid值 key=guid value=path Dictionary <string, ESpriteCnf> png_guid_map = ESpriteHelper.GetAllSpriteInfo(); // 3.分析prefab中的guid是否被引用 int ui_prefab_length = SpriteUnUseConst.ui_prefab_root_dirs.Length; for (int ui_prefab_index = 0; ui_prefab_index < ui_prefab_length; ui_prefab_index++) { // 读取所有的prefab string[] prefabs_path = Directory.GetFiles(SpriteUnUseConst.ui_prefab_root_dirs[ui_prefab_index], "*.prefab", SearchOption.AllDirectories); int length = prefabs_path.Length; for (int i = 0; i < length; i++) { string path = prefabs_path[i]; EditorUtility.DisplayProgressBar("获取引用关系", path, (float)i / length); // 读取指定位置的prefab的Guid值 List <string> guid_list = EGuidHelper.GetGuidsByFile(path); FileCompare(png_guid_map, guid_list); } } EditorUtility.ClearProgressBar(); // 没有被引用的guid写入到txt中 WriteUnUseFiles(png_guid_map); }
// 检索指定UI中的所有Image所用的图集 public static void QueryTexture() { // 原理:找到Prefab上的所有的guid值和所有的纹理和图集做比较 // 通过Sprite的guid来查询Sprite的详细信息 // 1.其中的Guid和Packing Tag <Key=Guid,Value=PackingTag> Dictionary <string, ESpriteCnf> all_sprite_guids = ESpriteHelper.GetAllSpriteInfo(); // 2.查找Prefab的实际保存的路径 string path = EPrefabHelper.FindPrefabPath(Selection.activeGameObject); // 3.读取指定位置的prefab的Guid值集合 List <string> guid_list = EGuidHelper.GetGuidsByFile(path); // 4.统计用到的纹理tag List <string> sprite_packing_tags = new List <string>(); // 5.统计使用到的空的tag List <ESpriteCnf> empty_list = new List <ESpriteCnf>(); int length = guid_list.Count; for (int i = 0; i < length; i++) { if (!all_sprite_guids.ContainsKey(guid_list[i])) { continue; } ESpriteCnf info = all_sprite_guids[guid_list[i]]; if (string.IsNullOrEmpty(info.packingtag)) { empty_list.Add(info); continue; } if (sprite_packing_tags.Contains(info.packingtag)) { continue; } sprite_packing_tags.Add(info.packingtag); } Debug.Log("使用到的Sprite Packing Tag Count:" + sprite_packing_tags.Count); for (int i = 0; i < sprite_packing_tags.Count; i++) { Debug.Log(sprite_packing_tags[i]); } Debug.Log("没有使用Sprite Packing Tag 或者是Texture 的"); for (int i = 0; i < empty_list.Count; i++) { Debug.Log("Path:" + empty_list[i].path); } // 输出相关信息 }
public void SetPath(string full_path) { // //Regex packingtag_reg = new Regex(@" spritePackingTag: ([a-f0-9]{32})"); path = full_path.Substring(0, full_path.Length - 5); string meta_text = File.ReadAllText(full_path); packingtag = ESpriteHelper.FindSpritePackingTag(meta_text); Regex guid_reg = new Regex(@"guid: ([a-f0-9]{32})"); Match matcher = guid_reg.Match(meta_text); guid = matcher.Groups[1].Value; }