Unity 3D
来源:互联网 发布:全国省市区sql 2017 编辑:程序博客网 时间:2024/06/07 08:05
Unity 3D - 编辑器扩展之删除未使用资源 :
C#代码 :
using System.Collections.Generic;using UnityEngine;using UnityEditor;using System.IO;using System.Linq;namespace CZGame{ public class ShowAllNotUseResource : EditorWindow { private List<string> checkType = new List<string>(); private List<string> allResource = new List<string>(); //所有使用资源 private List<string> notUseReource = new List<string>(); //没有使用过的资源 Dictionary<string, List<string>> mapReferenceOtherModulePref = new Dictionary<string, List<string>>(); Vector2 scrollPos = Vector2.zero; private void StartCheck() { List<string> withoutExtensions = new List<string>() { ".prefab" }; string[] files = Directory.GetFiles(Application.dataPath + "/GameRes/UIPrefab", "*.*", SearchOption.AllDirectories) .Where(s => withoutExtensions.Contains(Path.GetExtension(s).ToLower())).ToArray(); List<string> withoutExtensions2 = new List<string>() { ".png",".jpg" }; //所有project 里面的资源 string[] UIReource = Directory.GetFiles(Application.dataPath + "/GameRes/UI", "*.*", SearchOption.AllDirectories) .Where(s => withoutExtensions2.Contains(Path.GetExtension(s).ToLower())).ToArray(); for (int i = 0; i < UIReource.Length; i++) { UIReource[i] = UIReource[i].Replace("\\", "/"); int index = UIReource[i].IndexOf("Assets"); UIReource[i] = UIReource[i].Substring(index); } mapReferenceOtherModulePref.Clear(); float count = 0; foreach (string file in files) { count++; EditorUtility.DisplayProgressBar("Processing...", "检索中....", count / files.Length); string strFile = file.Substring(file.IndexOf("Asset")).Replace('\\', '/'); string[] dependenciesFiles = AssetDatabase.GetDependencies(strFile, false); foreach (string depFile in dependenciesFiles) { bool isNeedShow = false; foreach (string type in checkType) { //存在设置类型 需要显示 if (depFile.IndexOf(type) > -1) { isNeedShow = true; break; } } if (isNeedShow == false) { continue; } allResource.Add(depFile); } } EditorUtility.ClearProgressBar(); for (int i = 0; i < UIReource.Length; i++) { bool isUse = false; foreach (string usePath in allResource) { if (UIReource[i] == usePath) { isUse = true; break; } } if (isUse == false) { notUseReource.Add(UIReource[i]); } } } void OnGUI() { EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("列出所有未使用过的图片", GUILayout.Width(200))) { allResource = new List<string>(); notUseReource = new List<string>(); checkType.Clear(); checkType.Add(".jpg"); checkType.Add(".png"); StartCheck(); } if (GUILayout.Button("删除所有 !", GUILayout.Width(200))) { float count = 0; foreach (var path in notUseReource) { count++; EditorUtility.DisplayProgressBar("Processing...", "删除中... ("+ count + "/ " + notUseReource.Count + ")", count / notUseReource.Count); File.Delete(path); AssetDatabase.Refresh(); } EditorUtility.ClearProgressBar(); } EditorGUILayout.EndHorizontal(); scrollPos = EditorGUILayout.BeginScrollView(scrollPos); foreach (var path in notUseReource) { EditorGUILayout.BeginHorizontal(); Texture2D t = (Texture2D)AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)); EditorGUILayout.ObjectField(t, typeof(Texture2D), false); if (GUILayout.Button("删除", GUILayout.Width(200))) { File.Delete(path); AssetDatabase.Refresh(); } EditorGUILayout.Space(); EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); } }}
阅读全文
0 0
- Unity 3D
- unity 3d 注意事项
- Unity 3d 摄像头
- Unity 3D 使用
- Unity 3D--PlayerPrefs
- Unity 3d
- Unity 3D俄罗斯方块
- unity 3d 多开
- UNITY 3D笔记
- Unity 3D接触
- unity 3d
- Unity 3D简介
- Unity 3D 琐记
- unity 3d 视频
- Unity 3D 光源
- Unity 3D FingerID
- 再议Unity 3D
- unity 3d 网址
- 1015 最大公约数和最小公倍数
- 通过nginx配置文件抵御攻击,防御CC攻击的经典思路!
- 生产web应用java内存及回收配置
- 再次用openssl求SHA1
- PHP面向对象之重载
- Unity 3D
- dll加壳
- 欢迎使用CSDN-markdown编辑器
- mysql的批量新增和批量修改
- Linux系统指令
- Jenkins基础入门-9-构建触发器之项目之间依赖关系
- <c语言经典100例>c16 规律题
- Laravel--包管理器之composer
- 2103 玛德之杖