[MenuItem("Assets/查找选中资源依赖关系",false, 0)]
public static void FindDependencies()
{
foreach (var guid in Selection.assetGUIDs)
{
string path = AssetDatabase.GUIDToAssetPath(guid);
foreach (var dependenciePath in AssetDatabase.GetDependencies(path, false))
{
if(path != dependenciePath && !dependenciePath.Contains("cs"))
Debug.LogError(string.Format("path = {0} 依赖 > {1}", path, dependenciePath));
}
}
Debug.Log("查找依赖结束");
}
[MenuItem("Assets/查找选中资源反向依赖关系", false, 1)]
public static void FindReverseDependencies()
{
Dictionary> dDependencies = new Dictionary>();
foreach (var guid in Selection.assetGUIDs)
{
string t = AssetDatabase.GUIDToAssetPath(guid);
dDependencies.Add(t, new List());
}
string[] guids = AssetDatabase.FindAssets("t:Prefab t:Material t:Scene");
for (int i = 0; i < guids.Length; i++)
{
string guid = guids[i];
string path = AssetDatabase.GUIDToAssetPath(guid);
if (EditorUtility.DisplayCancelableProgressBar("资源依赖关系查找中", path, (float)(i + 1) / guids.Length))
{
EditorUtility.ClearProgressBar();
return;
}
foreach (var dependenciePath in AssetDatabase.GetDependencies(path, false))
{
if (path != dependenciePath)
{
if (dDependencies.TryGetValue(dependenciePath, out List list))
{
list.Add(path);
}
}
}
}
foreach (var kv in dDependencies)
{
kv.Value.ForEach((dependenciePath) =>
{
Debug.LogError(string.Format("path = {0} 被 > {1} 依赖", kv.Key, dependenciePath));
});
}
EditorUtility.ClearProgressBar();
Debug.Log("查找依赖结束");
}
查找资源依赖、反向查找资源被依赖关系。
该工具的意义用于打AB的时候 可以查找跨模块引用的资源并列举出来!



