private static List<GameObject> GetPrefabs()
{
List<GameObject> prefabList = new List<GameObject>();
获取场景所有物体
GameObject[] tmpObjs = Resources.FindObjectsOfTypeAll<GameObject>() as GameObject[];
//GameObject[] tmpObjs = Object.FindObjectsOfType<GameObject>();
//if (tmpObjs != null && tmpObjs.Length > 0)
// prefabList.AddRange(tmpObjs);
//获取Project所有物体
//获取Asset文件夹下所有Prefab的GUID
string[] ids = AssetDatabase.FindAssets("t:Prefab", new string[] { "Assets" });
for (int i = 0; i < ids.Length; i++)
{
//根据GUID获取路径
string tempPath = AssetDatabase.GUIDToAssetPath(ids[i]);
if (!string.IsNullOrEmpty(tempPath))
{
//根据路径获取Prefab(GameObject)
GameObject tempObj = AssetDatabase.LoadAssetAtPath(tempPath, typeof(GameObject)) as GameObject;
if (tempObj != null)
{
prefabList.Add(tempObj);
Collider tempColl = tempObj.GetComponent<Collider>();
if (tempColl != null)
{
//Do something
}
}
}
}
//
return prefabList;
}
本文来自博客园,作者:萧然CS,转载请注明原文链接:https://www.cnblogs.com/z-c-s/p/15112887.html
浙公网安备 33010602011771号