Here's what I did without using *Resources.FindObjectsOfTypeAll*
Also unlike *FindObjectsOfTypeAll*, this one returns the array elements in a parent->children order.
**Edit:** Replaced main foreach loops with for loops for better performance.
void Start()
{
List allGOs = new List();
GameObject[] rootGOs = gameObject.scene.GetRootGameObjects();
for (int i = 0; i < rootGOs.Length; i++)
GetAllChildren(rootGOs[i].transform, allGOs);
//Print them all out
foreach (GameObject g in allGOs)
Debug.Log(g.name);
}
void GetAllChildren(Transform current, List arrayToFill)
{
arrayToFill.Add(current.gameObject);
for (int i = 0; i < current.childCount; i++)
GetAllChildren(current.GetChild(i), arrayToFill);
}
↧