写在前面:
项目开发迭代过程中,UI资源的换版,会造成很多旧资源的冗余,而人工删除资源麻烦在于无法区分这个资源是不是还有地方再用,此工具的目的是提供一个可视化的界面,根据资源名称确定其所在图集,并且列出预制体对于改资源的引用,同时显示图片的大小,预览,路径等信息。为UI资源的梳理提供便利。
布局如下:
代码如下:
/*
图集资源管理器
1:查询UI资源
2:图集查重
3:资源引用处理
4:资源删除
author: tianrujie
date : 2018/5/5
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using ExcelDataReader;
using UnityEditor;
using excel2json;
using System.Text;
using System.Diagnostics;
public class UIAssetTool : EditorWindow {
//图集存放位置
private string AtlasWorkSpace = "Assets/AssetBundles/UI/Prefab/Atlas/";
//图集小图资源存放位置
private string AtlasAssetpath = "Assets/UI/UITexture/";
//UI预制体资源位置
private string PrefabAssetpath = "Assets/AssetBundles/UI/Prefab/";
public enum OperateType
{
atlasFilter = 1, //图集资源查重
assetReferenceFind = 2, //资源引用查询
}
[MenuItem("Tools/UIAssetTool")]
static void RunTool()
{
Rect re = new Rect(0, 0, 1000, 500);
UIAssetTool window = (UIAssetTool)EditorWindow.GetWindowWithRect(typeof(UIAssetTool), re, true, "UI资源管理");
window.Show();
window.InitData ();
}
//图集搜索文本
private string searchAtlas = string.Empty;
//资源搜索文本
private string searchSprite = string.Empty;
//当前选中图集
private string selecitionAtlas = string.Empty;
//当前选中资源
private string selecitionSprite = string.Empty;
//当前选中引用
private string selectionRef = string.Empty;
//图集列表
private List<string> AtlasList = new List<string>();
//图集资源容器
private Dictionary<string,List<string>> AtlasAssetDic = new Dictionary<string, List<string>>();
//<图片名称---图集>字典
private Dictionary<string,List<string>> SpriteLinkDic = new Dictionary<string, List<string>>();
//图片的引用
private Dictionary<string,List<string>> SpriteReference = new Dictionary<string, List<string>>();
/// <summary>
/// 初始化数据
/// </summary>
/// <returns><c>true</c>, if data was inited, <c>false</c> otherwise.</returns>
bool InitData()
{
AtlasList.Clear ();
AtlasAssetDic.Clear ();
DirectoryInfo dic = new DirectoryInfo (AtlasWorkSpace);
FileInfo[] atlases = dic.GetFiles ();
if (atlases == null)
return false;
for (int i = 0; i < atlases.Length; i++)
{
if (atlases [i].Name.Contains ("meta"))
continue;
AtlasList.Add (atlases[i].Name);
if (!AtlasAssetDic.ContainsKey (atlases [i].Name))
{
UIAtlas atlas = AssetDatabase.LoadAssetAtPath<UIAtlas>(AtlasWorkSpace + atlases [i].Name