反向搜索某个资源被哪里引用,比如贴图被那个资源使用了,可以利用ripgrep这样搜索会秒出结果。如下图所示,拖入待搜索的贴图,然后搜索它被哪里用了。
rg.exe 下载 https://github.com/BurntSushi/ripgrep/releases
代码利用 rg.exe -l guid 搜索,最终显示在界面中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
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 如果能引用的话就可以找到