概要
Projectビューで選択中のアセットから共通して参照されているアセットを参照されている数が多い順にログに出力するスクリプト。
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
public static class AssetUtility
{
[MenuItem("Assets/GetCommonDependencies")]
public static void GetCommonDependenciesInSelection()
{
var assetPaths = Selection.assetGUIDs.Select(guid => AssetDatabase.GUIDToAssetPath(guid)).Distinct();
GetCommonDependencies(assetPaths);
}
public static void GetCommonDependencies(IEnumerable<string> assetPaths)
{
var dependencies = new List<string[]>();
foreach (var assetPath in assetPaths)
{
dependencies.Add(AssetDatabase.GetDependencies(assetPath, true));
}
var assetPathCounts = new Dictionary<string, int>();
foreach (var temp in dependencies)
{
foreach (var assetPath in temp)
{
int count;
assetPathCounts.TryGetValue(assetPath, out count);
assetPathCounts[assetPath] = count + 1;
}
}
foreach (var kvp in assetPathCounts.OrderByDescending(kvp => kvp.Value))
{
if (kvp.Value > 1)
{
Debug.Log($"{kvp.Key}: {kvp.Value} references");
}
}
}
}