搜了一下网上的 关于资源引用查找的 只有 查找大概的引用预设,并不能显示具体到哪个节点引用的。所有自己写了一个,分享出来。欢迎大佬指点
话不多说,直接上代码
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
public class FindAssetsImpro
{
private static readonly string[] searchFolders = {
"Assets" };
private static readonly string[] searchTarget = {
"t:Prefab", "t:Material" };
private static Dictionary<string, string> tempGUIDDic;
[MenuItem("Assets/查找该资源预设引用位置", false, 10)]
private static void FindAss()
{
if (tempGUIDDic == null) tempGUIDDic = new Dictionary<string, string>();
tempGUIDDic.Clear();
string curentGUID = "";
System.Type type;
Dictionary<string, string> spriteFileIDDic = null;
List<MatchContent> AlreadyMatchList = new List<MatchContent>();
Dictionary<string, Object> spriteNmeObjDic = new Dictionary<string, Object>();
Dictionary<string, List<System.Action>> texturePrintAct = new Dictionary<string, List<System.Action>>();
string spriteFileName = string.Empty;
if (EditorSettings.serializationMode != SerializationMode.ForceText) EditorSettings.serializationMode = SerializationMode.ForceText;
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
string selectionName = Selection.activeObject.name;
type = Selection.activeObject.GetType();
if (type == typeof(UnityEngine.Texture2D) || type == typeof(UnityEngine.Sprite))
{
spriteFileIDDic = GetTexture2DSpritfileIDDic(path, out spriteNmeObjDic);
if (type == typeof(UnityEngine.Sprite)) spriteFileName = Selection.activeObject.name;
}
if (!string.IsNullOrEmpty(path))
{
string guid = AssetDatabase.AssetPathToGUID(path);
List<string> guidsList = new List<string>();
for (int i = 0; i < searchTarget.Length; i++)
{
guidsList.AddRange(AssetDatabase.FindAssets(searchTarget[i], searchFolders));
}
List<string> fs = new List<string>();
for (int i = 0; i < guidsList.Count; i++)
{
fs.Add(AssetDatabase.GUIDToAssetPath(GUIDS[i]));
}
string[] files = fs.ToArray();
int startIndex = 0;
int matchCount = 0;
EditorApplication.update = delegate ()
{
bool isCancel = EditorUtility.DisplayCancelableProgressBar("匹配资源中", files[startIndex], (float)startIndex / (float)files.Length);
bool isHave = false;
foreach (var item in AssetDatabase.GetDependencies(files[startIndex]))
{
if (!tempGUIDDic.TryGetValue(item, out curentGUID))
{
curentGUID = AssetDatabase.AssetPathToGUID(item);
tempGUIDDic[item] = curentGUID;
}
if (string.Equals(guid, curentGUID))
{
isHave = true;
break;
}
}
if (!isHave)
{
startIndex++;
}
else
{
string objTxt = File.ReadAllText(files[startIndex]);
if (Regex.IsMatch(objTxt, guid))
{
string delimiter = string.Empty;
for (int i = 0; i < specialCharacters.Length; i++)
{
if (!Regex.IsMatch(objTxt, "\\" + specialCharacters[i]))
{
delimiter = specialCharacters[i];
break;
}
}
if (string.IsNullOrEmpty(delimiter))
{
UnityEngine.Debug.LogError("No special symbols to split text.Please add some special symbols to specialCharacters");
EditorUtility.ClearProgressBar();
EditorApplication.update = null;
}
string[] objTxtArry = SelectText(objTxt, "---", delimiter);
var matchContent = new MatchContent(guid) {
type = type };
if (spriteFileIDDic != null)
{
matchContent.spriteFileIDDic = spriteFileIDDic;
if (type == typeof(UnityEngine.Sprite)) matchContent.spriteFileId = spriteFileIDDic.FirstOrDefault(q => q.Value == spriteFileName).Key;
}
var tempList = CheckOut(objTxtArry, matchContent, files[startIndex], ref matchCount, ref texturePrintAct, spriteNmeObjDic)