//查找本资源被哪些资源引用 private static void FindReferencesByAssets(string assetPath) { /* if(Directory.Exists(assetPath)) * { * FindReferencesInProject2.FindAssetsByRG(assetPath); * } * else * { * string appDataPath = Path.Combine(Application.dataPath, AddressableTools.Assets_Package ); * string selectedAssetGUID = AssetDatabase.AssetPathToGUID(assetPath); * FindReferencesInProject2.FindByRG(selectedAssetGUID,appDataPath); * } */ /* * if(Directory.Exists(assetPath)) * { * FindReferences.FindByArtToolsWindow(assetPath); * } * else * { * string[] sArray = {assetPath}; * FindReferences.FindAssetsByArtToolsWindow(sArray); * } */ FindReferences01.FindThread(assetPath); }
//[MenuItem("Assets/Find References Thread",false,10)] public static void FindThread(string path, bool outExcel = false) { refDic.Clear(); EditorSettings.serializationMode = SerializationMode.ForceText; AssetDatabase.Refresh(); //string path = AssetDatabase.GetAssetPath(Selection.activeObject); if (!string.IsNullOrEmpty(path)) { List <string> _AssetGuidList = new List <string>(); List <string> _AssetNameList = new List <string>(); if (Directory.Exists(path)) { string[] assetPathsFromFolder = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories); foreach (var tempPath in assetPathsFromFolder) { if (!tempPath.EndsWith(".meta")) { var assetFindPath = GetRelativeAssetsPath(tempPath); _AssetNameList.Add(assetFindPath); _AssetGuidList.Add(AssetDatabase.AssetPathToGUID(assetFindPath)); } } } else { _AssetGuidList.Add(AssetDatabase.AssetPathToGUID(path)); _AssetNameList.Add(path); } ThreadPars[] threadParses = new ThreadPars[ThreadCount]; for (int i = 0; i < ThreadCount; i++)//添加查找的udid { threadParses[i] = new ThreadPars(); threadParses[i].AssetGuidList = _AssetGuidList; threadParses[i].AssetNameList = _AssetNameList; } List <string> withoutExtensions = new List <string>() { ".prefab", ".unity", ".mat", ".asset" }; string[] files = Directory.GetFiles(Path.Combine(Application.dataPath, "AssetsPackage"), "*.*", SearchOption.AllDirectories) .Where(s => withoutExtensions.Contains(Path.GetExtension(s).ToLower())).ToArray(); for (int i = 0; i < files.Length; i++)//添加要查找的资源文件 { int index = i % ThreadCount; threadParses[index].CheckAssetList.Add(files[i]); } string[] csFiles = Directory.GetFiles(Application.dataPath, "*.cs", SearchOption.AllDirectories) .Where(s => s.IndexOf("/editor/", System.StringComparison.OrdinalIgnoreCase) < 0).ToArray(); for (int i = 0; i < csFiles.Length; i++)//添加要查找的CS文件 { int index = i % ThreadCount; threadParses[index].CheckCSList.Add(csFiles[i]); } ThreadRun[] tRun = new ThreadRun[ThreadCount]; int finishedState = ThreadCount; IAsyncResult[] results = new IAsyncResult[ThreadCount]; _updateDelegate = delegate { var finishedCount = 0; for (int i = 0; i < ThreadCount; i++) { if (results[i].IsCompleted) { ++finishedCount; } } EditorUtility.DisplayProgressBar("匹配资源中", string.Format("进度:{0}", finishedCount), (float)finishedCount / ThreadCount); if (finishedCount >= finishedState) { for (int i = 0; i < ThreadCount; i++) { Dictionary <string, List <string> > temRunThreadData = tRun[i].EndInvoke(results[i]); foreach (var keyValue in temRunThreadData) { var key = keyValue.Key; if (key.Contains("/") || key.Contains("\\")) { key = AssetDatabase.AssetPathToGUID(key); } if (refDic.ContainsKey(key)) { refDic[key].AddRange(keyValue.Value); } else { refDic.Add(key, keyValue.Value); } } } EditorUtility.ClearProgressBar(); EditorApplication.update -= _updateDelegate; if (outExcel) { OutputToExcel(); } else { FindReferences01 window = (FindReferences01)EditorWindow.GetWindow(typeof(FindReferences01)); window.Show(); } } }; for (int i = 0; i < ThreadCount; i++) { tRun[i] = ThreadFind; results[i] = tRun[i].BeginInvoke(threadParses[i], null, null); } EditorApplication.update += _updateDelegate; } }
public static void ResourceAnalysis() { FindReferences01.ResourceAnalysis(); }