public override void OnInspectorGUI() { serializedObject.Update(); if (!initialized) { for (var i = 0; i < length; i++) { var fold = Attribute.GetCustomAttribute(objectFields[i], typeof(FoldoutAttribute)) as FoldoutAttribute; Cache c; if (fold == null) { if (prevFold != null && prevFold.foldEverything) { if (!cache.TryGetValue(prevFold.name, out c)) { cache.Add(prevFold.name, new Cache { atr = prevFold, types = new HashSet <string> { objectFields[i].Name } }); } else { c.types.Add(objectFields[i].Name); } } continue; } prevFold = fold; if (!cache.TryGetValue(fold.name, out c)) { cache.Add(fold.name, new Cache { atr = fold, types = new HashSet <string> { objectFields[i].Name } }); } else { c.types.Add(objectFields[i].Name); } } var property = serializedObject.GetIterator(); var next = property.NextVisible(true); if (next) { do { HandleProp(property); } while (property.NextVisible(false)); } } if (props.Count == 0) { DrawDefaultInspector(); return; } initialized = true; using (new EditorGUI.DisabledScope("m_Script" == props[0].propertyPath)) { EditorGUILayout.PropertyField(props[0], true); } EditorGUILayout.Space(); foreach (var pair in cache) { var rect = EditorGUILayout.BeginVertical(); EditorGUILayout.Space(); EditorGUI.DrawRect(new Rect(rect.x - 1, rect.y - 1, rect.width + 1, rect.height + 1), colors.col0); EditorGUI.DrawRect(new Rect(rect.x - 1, rect.y - 1, rect.width + 1, rect.height + 1), colors.col1); pair.Value.expanded = EditorGUILayout.Foldout(pair.Value.expanded, pair.Value.atr.name, true, style != null ? style : EditorStyles.foldout); EditorGUILayout.EndVertical(); rect = EditorGUILayout.BeginVertical(); EditorGUI.DrawRect(new Rect(rect.x - 1, rect.y - 1, rect.width + 1, rect.height + 1), colors.col2); if (pair.Value.expanded) { EditorGUILayout.Space(); { for (int i = 0; i < pair.Value.props.Count; i++) { EditorGUI.indentLevel = 1; EditorGUILayout.PropertyField(pair.Value.props[i], new GUIContent(pair.Value.props[i].name.FirstLetterToUpperCase()), true); if (i == pair.Value.props.Count - 1) { EditorGUILayout.Space(); } } } } EditorGUI.indentLevel = 0; EditorGUILayout.EndVertical(); EditorGUILayout.Space(); } for (var i = 1; i < props.Count; i++) { EditorGUILayout.PropertyField(props[i], true); } serializedObject.ApplyModifiedProperties(); EditorGUILayout.Space(); }
public void Dispose() { props.Clear(); types.Clear(); atr = null; }