//public void UpdateGOs() //{ // Debug.Log("Updating"); // UnityEngine.GameObject[] objects = FindObjectsOfType(typeof(GameObject)) as GameObject[]; // List<GameObject> rootGos = FindRoots(objects); // _gos.RemoveAll(t => !rootGos.Contains(t.GameObject)); // _gos.AddRange(FindNewGos(rootGos)); // foreach (GameObject gameObject in rootGos.Where(g => _gos.All(j => j.GameObject != g))) // { // _gos.AddRange(new GameObjectTree(gameObject)); // } //} //private List<GameObject> FindRoots(GameObject[] objects) //{ // List<GameObject> roots = new List<GameObject>(); // foreach (GameObject go in objects) // { // if (go != null && go.transform.parent) // { // roots.Add(go); // } // } // return roots; //} public IEnumerable <GameObjectTree> SceneRoots() { UnityEngine.Object[] objects = FindObjectsOfType(typeof(GameObject)); _gos.Clear(); foreach (UnityEngine.Object o in objects) { GameObject go = o as GameObject; if (go != null && go.transform.parent == null) { GameObjectTree tree = new GameObjectTree(go); FillChildren(tree, go); _gos.Add(tree); } } if (_filterJunk) { return(_filter.FilterJunk(_gos)); } return(_gos); }
public GameObjectTree AddChild(GameObject go) { var tree = new GameObjectTree(go); children.Add(tree); return(tree); }
private void FillChildren(GameObjectTree tree, GameObject go) { foreach (Transform transform in go.transform) { tree.AddChild(transform.gameObject); FillChildren(tree.GetChild(tree.Count - 1), transform.gameObject); } }
private void DrawObject(GameObjectTree treeGo, int spacing) { GUILayout.BeginHorizontal(); GUILayout.Space(spacing); if (!open.Contains(treeGo.GameObject)) { if (GUILayout.Button("+", GUILayout.Width(20))) { open.Add(treeGo.GameObject); } } else { if (GUILayout.Button("-", GUILayout.Width(20))) { open.Remove(treeGo.GameObject); } } if (GUILayout.Button(treeGo.GameObject.name, GUI.skin.label)) { _selected = treeGo.GameObject; } GUILayout.EndHorizontal(); if (open.Contains(treeGo.GameObject)) { foreach (GameObjectTree childTreeGo in treeGo.GetChildren()) { DrawObject(childTreeGo, spacing + 10); } } }