unity editor 查找“被引用”的asset
https://github.com/networm/FindReferencesInProject/blob/master/FindReferencesInProject.cs
打印出被谁依赖:
1 using System.Collections; 2 using System.Collections.Generic; 3 using UnityEngine; 4 using UnityEditor; 5 6 public class FindReferencesInProject 7 { 8 private const string MenuItemText = "Assets/Find References In Project"; 9 10 [MenuItem(MenuItemText, false, 25)] 11 public static void Find() 12 { 13 var sw = new System.Diagnostics.Stopwatch(); 14 sw.Start(); 15 16 var referenceCache = new Dictionary<string, List<string>>(); 17 18 string[] guids = AssetDatabase.FindAssets(""); 19 foreach (string guid in guids) 20 { 21 string assetPath = AssetDatabase.GUIDToAssetPath(guid); 22 string[] dependencies = AssetDatabase.GetDependencies(assetPath, false); 23 24 foreach (var dependency in dependencies) 25 { 26 if (referenceCache.ContainsKey(dependency)) 27 { 28 if (!referenceCache[dependency].Contains(assetPath)) 29 { 30 referenceCache[dependency].Add(assetPath); 31 } 32 } 33 else 34 { 35 referenceCache[dependency] = new List<string>(){ assetPath }; 36 } 37 } 38 } 39 40 Debug.Log("Build index takes " + sw.ElapsedMilliseconds + " milliseconds"); 41 42 string path = AssetDatabase.GetAssetPath(Selection.activeObject); 43 Debug.Log("Find: " + path, Selection.activeObject); 44 if (referenceCache.ContainsKey(path)) 45 { 46 foreach (var reference in referenceCache[path]) 47 { 48 Debug.Log(reference, AssetDatabase.LoadMainAssetAtPath(reference)); 49 } 50 } 51 else 52 { 53 Debug.LogWarning("No references"); 54 } 55 56 referenceCache.Clear(); 57 } 58 59 [MenuItem(MenuItemText, true)] 60 public static bool Validate() 61 { 62 if (Selection.activeObject) 63 { 64 string path = AssetDatabase.GetAssetPath(Selection.activeObject); 65 return !AssetDatabase.IsValidFolder(path); 66 } 67 68 return false; 69 } 70 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
2016-03-28 C#使用正则表达式检测数字 char 和韩文