unity在editor下查找项目中没有使用的图集

因为项目迭代时间过长,项目中有许多已经不再使用的图集,需要进行删除不再使用图集。以达到整理资源的目的。using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using System.IO;
public class FindAtlasNoUseUtil : EditorWindow
{
protected static List mAtlasList = new List();
protected static List mUseingAtlasList = new List();
protected static string[] mAtlasPath = new string[] { “Assets/Resources/Atlas” };//图集的路径
protected static List mObj = new List();
[MenuItem(“Tools/查找NGUI图集中没有使用的图集”)]
static void FindAtlasNoUse()
{
FindnAllAtlas();
FindNoUseAltasInGame();
}
static void FindnAllAtlas()
{
string[] guids = AssetDatabase.FindAssets(“t:GameObject”, mAtlasPath);
List paths = new List();
guids.ToList().ForEach(m => paths.Add(AssetDatabase.GUIDToAssetPath(m)));
paths.ForEach(p => mAtlasList.Add(AssetDatabase.LoadAssetAtPath(p, typeof(UIAtlas)) as UIAtlas));
for (int i = 0; i < mAtlasList.Count; i++)
{
if (i < mAtlasList.Count && mAtlasList[i] == null)
{
mAtlasList.Remove(mAtlasList[i]);
i–;
}
}
}
static void FindNoUseAltasInGame()
{
mObj.Clear();
mUseingAtlasList.Clear();
string path = Application.dataPath + “/Resources/Layout/NGUIPrefab/”;
string[] directoryPath = Directory.GetFiles(path, “*”, SearchOption.AllDirectories);
foreach (string value in directoryPath)
{
if (value.Contains(".meta"))
{
continue;
}    
string strTempPath = value.Replace(@"", “/”);
strTempPath = strTempPath.Substring(strTempPath.IndexOf(“Assets”));
Object obj = AssetDatabase.LoadAssetAtPath(strTempPath, typeof(Object));
mObj.Add(obj);
}
for (int i = 0; i < mObj.Count; i++)
{
GameObject gameObj = mObj[i] as GameObject;
UISprite[] sprites = gameObj.transform.GetComponentsInChildren(true);
for (int j = 0; j < sprites.Length; j++)
{
if (sprites[j] != null)
{
if (!mUseingAtlasList.Contains(sprites[j].atlas))
{
mUseingAtlasList.Add(sprites[j].atlas);
}
}
}
}
for (int i = 0; i < mAtlasList.Count; i++)
{
if (!mUseingAtlasList.Contains(mAtlasList[i]))
{
Debug.Log(“图集的名字:” + mAtlasList[i]);
}
}
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值