方法大量借鉴雨松大神的文章,
附上链接表示敬意
http://www.xuanyusong.com/archives/4207
好处是自己添加了可以多选操作
不好的是没有“”设置某些文件夹忽略“”的功能,那样可以节省不少时间
而且不能“”选中文件夹查找“,那样有些时候更方便
代码如下:
-
using UnityEngine;
-
using System.Collections;
-
using UnityEditor;
-
using System.IO;
-
using System.Linq;
-
using System.Text;
-
using System.Text.RegularExpressions;
-
using System.Collections.Generic;
-
using NUnit.Framework;
-
-
public
class
FindReferences
-
{
-
-
[
MenuItem("Assets/Find References", false, 10)]
-
static private void Find()
-
{
-
EditorSettings.serializationMode = SerializationMode.ForceText;
-
-
Object[] SelectedAsset = Selection.GetFiltered(
typeof(Object), SelectionMode.Assets|SelectionMode.ExcludePrefab );
-
//此处添加需要命名的资源后缀名,注意大小写。
-
string[] Filtersuffix =
new
string[] {
".prefab",
".mat",
".dds",
".png",
".jpg" ,
".shader" ,
".csv",
".wav",
".mp3"};
-
if (SelectedAsset.Length ==
0)
return;
-
foreach (Object tmpFolder
in SelectedAsset) {
-
string path = AssetDatabase.GetAssetPath(tmpFolder);
-
if (!
string.IsNullOrEmpty (path)) {
-
string guid = AssetDatabase.AssetPathToGUID (path);
-
List<
string> withoutExtensions =
new List<
string> (){
".prefab",
".unity",
".mat",
".asset" };
-
string[] files = Directory.GetFiles (Application.dataPath,
"*.*", SearchOption.AllDirectories)
-
.Where (s => withoutExtensions.Contains (Path.GetExtension (s).ToLower ())).ToArray ();
-
-
-
int num =
0;
-
for (
var i =
0; i < files.Length; ++i)
-
{
-
-
string file = files [i];
-
//显示进度条
-
EditorUtility.DisplayProgressBar(
"匹配资源",
"正在匹配资源中...",
1.0f * i / files.Length);
-
if (Regex.IsMatch (File.ReadAllText (file), guid)) {
-
Debug.Log (file, AssetDatabase.LoadAssetAtPath<Object> (GetRelativeAssetsPath (file)));
-
num++;
-
}
-
}
-
if (num ==
0) {
-
Debug.LogError (tmpFolder.name +
" 匹配到" + num +
"个",tmpFolder) ;
-
}
else
if (num ==
1) {
-
Debug.Log (tmpFolder.name +
" 匹配到" + num +
"个",tmpFolder) ;
-
}
else {
-
Debug.LogWarning (tmpFolder.name +
" 匹配到" + num +
"个",tmpFolder) ;
-
}
-
num =
0;
-
// int startIndex = 0;
-
// EditorApplication.update = delegate() {
-
// string file = files [startIndex];
-
//
-
// bool isCancel = EditorUtility.DisplayCancelableProgressBar ("匹配资源中", file, (float)startIndex / (float)files.Length);
-
//
-
// if (Regex.IsMatch (File.ReadAllText (file), guid)) {
-
// Debug.Log (file, AssetDatabase.LoadAssetAtPath<Object> (GetRelativeAssetsPath (file)));
-
// }
-
//
-
// startIndex++;
-
// if (isCancel || startIndex >= files.Length) {
-
//
-
// EditorApplication.update = null;
-
// startIndex = 0;
-
// Debug.Log ("匹配结束" + tmpFolder.name);
-
// }
-
//
-
// };
-
}
-
}
-
EditorUtility.ClearProgressBar ();
-
}
-
-
[
MenuItem("Assets/Find References", true)]
-
static private bool VFind()
-
{
-
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
-
return (!
string.IsNullOrEmpty(path));
-
}
-
-
static private string GetRelativeAssetsPath(string path)
-
{
-
return
"Assets" + Path.GetFullPath(path).Replace(Path.GetFullPath(Application.dataPath),
"").Replace(
'\\',
'/');
-
}
-
}
有时间再完善吧,现在的也够用了。
最近看到个插件
Unity资源断舍离(资源清理重复以及引用被引用查找)
地址:https://blog.youkuaiyun.com/akof1314/article/details/83589111
实现的很好