对资源进行相关操作的接口: AssetDatabase
// 获得指定路径下的 指定脚本的 所有预制体
public static List<T> GetAssetsWithScripts<T>(string path) where T : MonoBehaviour
{
T temp;
string assetPath;
GameObject asset;
List<T> assetList = new List<T>();
//对资源进行相关操作的接口AssetDatabase,获得路径下的所有预制体
//参数 过滤器 路径(字符串数组)
//guid Global Unique Identify 全局唯一ID
string[] guids = AssetDatabase.FindAssets("t:Prefab", new string[] {
path });
for (int i = 0; i < guids.Length; i++)
{
//获取资源路径
assetPath = AssetDatabase.GUIDToAssetPath(guids[i]);
//加载资源
asset = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
//判断资源下边是否绑定了T类型脚本
temp = asset.GetComponent<T>();
if (temp!= null)
{
assetList.Add(temp);
}
}
return assetList;
}