筛选冗余的图片资源
来源:互联网 发布:java工程师是干什么的 编辑:程序博客网 时间:2024/05/29 08:00
转载自:https://github.com/neoliang/FindUnUsedUITexture/blob/master/FindUnUnUsedUITexture.cs
using UnityEngine;using UnityEditor;using System.IO;using System.Linq;using System.Text.RegularExpressions;using System.Collections.Generic;using System.Text;using System;public static class LinqHelper { public static TSource Fold(this IEnumerable source, Func func, TSource id) { TSource r = id; foreach (var s in source) { r = func(r, s); } return r; } public static void ForEach (this IEnumerable source, Action action) { foreach (T element in source) action(element); } public static IEnumerable SelectI(this IEnumerable source, Func action) { int i = 0; foreach (var s in source) { yield return action(s, i); i += 1; } } public static TSource Reduce (this IEnumerable source, Func func) where TSource : new() { return Fold (source, func, new TSource()); } public static void ForEachI (this IEnumerable source, Action action) { int i = 0; foreach (T element in source) { action(element, i); i += 1; } }}public static class FindUnUnUsedUITexture{ static List getUUIDsInFile(string path) { StreamReader file = new StreamReader(path); List uuids = new List (); string line; while ((line = file.ReadLine()) != null) { var reg = new Regex(@"([a-f0-9]{32})"); var m = reg.Match(line); if (m.Success) { uuids.Add(m.Groups[0].Value); } } file.Close(); return uuids; } // Use this for initialization [MenuItem("Tools/UI冗余图片扫描")] public static void Scan() { var uiPrefabRootDir = EditorUtility.OpenFolderPanel("选择UIPrefab目录", "Assets",""); if (string.IsNullOrEmpty(uiPrefabRootDir)) { return; } var uiPicRootDir = EditorUtility.OpenFolderPanel("选择UIPrefab目录", "Assets", ""); if (string.IsNullOrEmpty(uiPicRootDir)) { return; } //find all meta and pic path var uuidReg = new Regex(@"guid: ([a-f0-9]{32})"); var pngs = Directory.GetFiles(uiPicRootDir, "*.meta", SearchOption.AllDirectories) .Select(p => "Assets/" + p.Replace('\\','/').Substring(Application.dataPath.Length+1)) .Where(p => { return p.EndsWith(".png.meta") || p.EndsWith(".jpg.meta") || p.EndsWith(".tag.meta"); }).ToList(); var uuid2path = new Dictionary (); pngs.ForEachI((png, i) => { var matcher = uuidReg.Match(File.ReadAllText(png)); var uuid = matcher.Groups[1].Value; if (uuid2path.ContainsKey(uuid)) { Debug.LogError("uuid dup" + uuid + " \n" + png + "\n" + uuid2path[uuid]); } else { uuid2path.Add(uuid, png.Substring(0,png.Length-5)); } EditorUtility.DisplayProgressBar("扫描图片中", png, (float)i / pngs.Count); }); //find all prefab and search pic uuid var prefabs = Directory.GetFiles(uiPrefabRootDir, "*.prefab", SearchOption.AllDirectories); var anims = Directory.GetFiles("Assets/", "*.anim", SearchOption.AllDirectories).Where(p => !p.Replace('\\', '/').Contains("Characters/")); var allFiles = prefabs.Concat(anims).ToList(); var alluuids = allFiles .SelectI((f, i) => { EditorUtility.DisplayProgressBar("获取引用关系", f, (float)i / allFiles.Count); return getUUIDsInFile(f); }).ToList().Aggregate((a, b) => a.Concat(b).ToList()).ToList(); EditorUtility.ClearProgressBar(); //rm used pic uuid var uuidshashset = new HashSet (alluuids); var em = uuidshashset.GetEnumerator(); while(em.MoveNext()) { var uuid = em.Current; uuid2path.Remove(uuid); } StringBuilder sb = new StringBuilder(); sb.Append("UnUsedFiles: "); sb.Append(uuid2path.Count); sb.Append("\n"); uuid2path.ForEach(kv => sb.Append(kv.Value +"\n")); File.WriteAllText("Assets/unusedpic.txt", sb.ToString()); EditorUtility.DisplayDialog("扫描成功", string.Format("共找到{0}个冗余图片\n请在Assets/unsedpic.txt查看结果",uuid2path.Count), "ok"); }}
阅读全文
0 0
- 筛选冗余的图片资源
- apk清除冗余资源
- AssetBundle资源冗余检测
- unity-AssetBundle资源冗余检测
- 图片资源的平铺
- 图片资源的平铺
- 【资源】我的图片
- 【资源】我的图片
- AndroidStudio小技巧 —— 优化代码之清理冗余的资源文件
- 删除Android工程中冗余资源
- iOS项目冗余资源扫描脚本
- Unity AssetBundle 冗余检测与资源分析
- DailyModi:每天筛选三组瞬间激发灵感的图片
- 正则表达式筛选出jpg、png的图片url
- 两幅图片逐个像素对比筛选不同的区域
- 冗余的New
- 数字图像的冗余
- 数字图像的冗余
- 暑假博客——ML第一天
- Swing之JPanel
- (初学者)求最大公约数和最小公倍数之更相减损术
- 一键改色
- 如何获取和修改分辨率
- 筛选冗余的图片资源
- C语言函数调用约定
- 怎么让Chrome支持小于12px 的文字?
- SpringBoot在自定义类中调用service层等Spring其他层
- 无缝滚动小练习—animation
- 如何去自定义一个Toast?
- angularjs 图片上传 回显
- Android 使用Scheme实现从网页启动APP
- [leetcode]617. Merge Two Binary Trees