void OnGUI() { if (Selection.activeGameObject != null && Selection.activeGameObject.GetComponent <ChildrenHide>() == null) { GUILayout.BeginHorizontal(); GUILayout.Label("nr of direct children here: " + Selection.activeGameObject.transform.childCount); if ((Selection.objects.Length > 1) && (GUILayout.Button("Add Hiders"))) { foreach (object o in Selection.objects) { GameObject g = o as GameObject; if (g != null && g.GetComponent <ChildrenHide>() == null) { ChildrenHide ch = g.AddComponent <ChildrenHide>(); } } } GUILayout.EndHorizontal(); } //else //GUILayout.Label("no selection"); if (chList == null || chList.Count == 0) { ReScan(); } for (int i = 0; i < chList.Count; i++) { if (chList[i] != null) { int crnmt = (int)chList[i].childrenVisbility; GUILayout.BeginHorizontal(); int enn = GUILayout.Toolbar(crnmt, ChildStateStrings); GUILayout.Label(chList[i].name); GUILayout.EndHorizontal(); if (crnmt != enn) { chList[i].childrenVisbility = (ChildrenHide.ChildVis)enn; } } } }
void OnSelectionChange() { GameObject o = Selection.activeGameObject; if (o == null) { return; } ChildrenHide h = o.GetComponentInParent <ChildrenHide>(); if (h != null) { if (h.childrenVisbility == ChildrenHide.ChildVis.HIDE) { EditorApplication.delayCall += () => Selection.activeGameObject = h.gameObject; } } }