This is kind of gross, but it works well:
public static List GetAllObjectsInScene(bool bOnlyRoot)
{
GameObject[] pAllObjects = (GameObject[])Resources.FindObjectsOfTypeAll(typeof(GameObject));
List pReturn = new List();
foreach (GameObject pObject in pAllObjects)
{
if (bOnlyRoot)
{
if (pObject.transform.parent != null)
{
continue;
}
}
if (pObject.hideFlags == HideFlags.NotEditable || pObject.hideFlags == HideFlags.HideAndDontSave)
{
continue;
}
if (Application.isEditor)
{
string sAssetPath = AssetDatabase.GetAssetPath(pObject.transform.root.gameObject);
if (!string.IsNullOrEmpty(sAssetPath))
{
continue;
}
}
pReturn.Add(pObject);
}
return pReturn;
}
↧