反向搜索某个资源被哪里引用,比如贴图被那个资源使用了,可以利用ripgrep这样搜索会秒出结果。如下图所示,拖入待搜索的贴图,然后搜索它被哪里用了。
rg.exe 下载 https://github.com/BurntSushi/ripgrep/releases
代码利用 rg.exe -l guid 搜索,最终显示在界面中
public class SearchWindows : EditorWindow
{
[MenuItem ("Assets/Search Reference")]
public static void OpenWindow ()
{
(EditorWindow.GetWindow(typeof(SearchWindows)) as SearchWindows).Search = Selection.activeObject;
}
public Object Search;
List<Object> SearchOut= new List<Object>();
private void OnGUI()
{
EditorGUILayout.BeginHorizontal();
GUILayout.Label ("Search:", EditorStyles.boldLabel);
Search = EditorGUILayout.ObjectField(Search, typeof(Object), true);
EditorGUILayout.EndHorizontal();
if (GUILayout.Button("Search!"))
{
if (Search != null)
{
SearchOut.Clear();
List<string> @out = new List<string>();
string path = AssetDatabase.GetAssetPath(Search);
if (!string.IsNullOrEmpty(path))
{
string guid = AssetDatabase.AssetPathToGUID(path);
string meta = AssetDatabase.GetTextMetaFilePathFromAssetPath(path);
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.WorkingDirectory = Application.dataPath;
p.StartInfo.FileName = $"{Application.dataPath}/../../Tools/Search/rg.exe";
p.StartInfo.Arguments = $"-l {guid}";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
while (!p.StandardOutput.EndOfStream)
{
string line = $"Assets/{p.StandardOutput.ReadLine().Replace("\","/")}";
if (line != meta)
{
var item = AssetDatabase.LoadAssetAtPath(line, typeof(Object));
if(item != null)
SearchOut.Add(item);
}
}
}
}
}
if (SearchOut.Count > 0)
{
GUILayout.Label("Out:", EditorStyles.boldLabel);
foreach (var o in SearchOut)
{
EditorGUILayout.ObjectField(o, typeof(Object), true);
}
}
}
}
- 本文固定链接: https://www.xuanyusong.com/archives/5073
- 转载请注明: 雨松MOMO于 雨松MOMO程序研究院 发表
捐 赠写博客不易,如果您想请我喝一杯星巴克的话?就进来看吧!


如果是二进制的资产引用就不会被查到,这个原理应该还是查所有text文本
二进制资产的meta文件中的GUID 如果能引用的话就可以找到