Unity扩展编辑器学习笔记--从路径下找到拥有某个组件类型的预设

时间:2022-09-10 15:39:18
 public static List<T> GetAssetsWithScript<T>(string path) where T:MonoBehaviour
{
T tmp;
string assetPath;
GameObject asset;
List<T> assetList = new List<T> ();
string[] guids = AssetDatabase.FindAssets ("t:Prefab", new string[] {path});
for (int i = ; i < guids.Length; i++)
{
assetPath = AssetDatabase.GUIDToAssetPath (guids[i]);
asset = AssetDatabase.LoadAssetAtPath(assetPath, typeof(GameObject)) as GameObject;
tmp = asset.GetComponent<T> ();
if (tmp != null)
{
assetList.Add (tmp);
}
}
return assetList;
}