private void _BuildChildControls(SECTR_LOD myLOD, SECTR_LOD.LODSet lodSet, Transform transform, bool rootTransform) { if (transform) { if (!rootTransform) { ++EditorGUI.indentLevel; } int numChildren = transform.childCount; bool expanded = false; if (!rootTransform) { GUI.enabled = transform.parent == myLOD.transform || lodSet.GetEntry(transform.parent.gameObject) != null; expanded = _DrawChildControl(myLOD, lodSet, transform, numChildren > 0); GUI.enabled = true; } if (expanded || rootTransform) { for (int childIndex = 0; childIndex < numChildren; ++childIndex) { _BuildChildControls(myLOD, lodSet, transform.GetChild(childIndex), false); } } } if (!rootTransform) { --EditorGUI.indentLevel; } }
private bool _DrawChildControl(SECTR_LOD myLOD, SECTR_LOD.LODSet lodSet, Transform transform, bool hasChildren) { string undoString = "Changed LOD"; bool expanded = false; float labelWidth = Screen.width * 0.3f; float checkWidth = 30; float buffer = 5; Rect propertyRect = EditorGUILayout.BeginHorizontal(GUILayout.Width(labelWidth)); if (hasChildren) { hierarchyFoldouts.TryGetValue(transform, out expanded); hierarchyFoldouts[transform] = EditorGUILayout.Foldout(expanded, transform.name); } else { EditorGUILayout.LabelField(transform.name, GUILayout.Width(labelWidth)); } EditorGUILayout.EndHorizontal(); SECTR_LOD.LODEntry entry = lodSet.GetEntry(transform.gameObject); bool isChecked = entry != null; bool newChecked = GUI.Toggle(new Rect(propertyRect.xMax + buffer, propertyRect.y, checkWidth, propertyRect.height), isChecked, GUIContent.none); if (newChecked != isChecked) { SECTR_Undo.Record(myLOD, undoString); if (newChecked) { entry = lodSet.Add(transform.gameObject, null); } else { lodSet.Remove(transform.gameObject); entry = null; } isChecked = newChecked; myLOD.Reset(); } if (entry != null && transform.GetComponent <Renderer>()) { Renderer newSource = (Renderer)EditorGUI.ObjectField(new Rect(propertyRect.xMax + checkWidth + buffer, propertyRect.y, Screen.width - (propertyRect.xMax + checkWidth + buffer * 2), propertyRect.height), GUIContent.none, entry.lightmapSource, typeof(Renderer), true); if (newSource != entry.lightmapSource) { SECTR_Undo.Record(myLOD, undoString); entry.lightmapSource = newSource; myLOD.Reset(); } } return(expanded); }