Unity获取Hierarchy中所有物体
void FindAllGameObject() { List<GameObject> roots = new List<GameObject>(); for (int i = 0; i < SceneManager.sceneCount; i++) { var scene = SceneManager.GetSceneAt(i); if (!scene.isLoaded) continue; roots.AddRange(scene.GetRootGameObjects()); } for (int i = 0; i < roots.Count; i++) { print(roots.name); } }
页:
[1]