From 85d38ea3d1ee0e7b3fc2c72601733fc0f9eac22d Mon Sep 17 00:00:00 2001 From: Nigg Date: Mon, 6 Sep 2021 16:26:26 +0200 Subject: [PATCH] #133 another small boost --- .../Scripts/Editor/NaughtyInspector.cs | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Assets/NaughtyAttributes/Scripts/Editor/NaughtyInspector.cs b/Assets/NaughtyAttributes/Scripts/Editor/NaughtyInspector.cs index 82e39b4b..649ace9b 100644 --- a/Assets/NaughtyAttributes/Scripts/Editor/NaughtyInspector.cs +++ b/Assets/NaughtyAttributes/Scripts/Editor/NaughtyInspector.cs @@ -60,7 +60,6 @@ protected virtual void OnDisable() ReorderableListPropertyDrawer.Instance.ClearCache(); } - public override void OnInspectorGUI() { if (!_anyNaughtyAttribute) @@ -77,9 +76,11 @@ public override void OnInspectorGUI() DrawButtons(); } - protected void GetSerializedProperties(ref List outSerializedProperties) + protected virtual void GetSerializedProperties(ref List outSerializedProperties) { outSerializedProperties.Clear(); + outSerializedProperties.TrimExcess(); + using (var iterator = serializedObject.GetIterator()) { if (iterator.NextVisible(true)) @@ -95,7 +96,7 @@ protected void GetSerializedProperties(ref List outSerializedPr } } - protected void DrawSerializedProperties() + protected virtual void DrawSerializedProperties() { serializedObject.Update(); @@ -108,24 +109,24 @@ protected void DrawSerializedProperties() } // Draw non-grouped serialized properties - foreach (var property in _nonGroupedSerializedProperty) + foreach (var naughtyProperty in _nonGroupedSerializedProperty) { - NaughtyEditorGUI.PropertyField_Layout(property, includeChildren: true); + NaughtyEditorGUI.PropertyField_Layout(naughtyProperty, includeChildren: true); } // Draw grouped serialized properties foreach (var group in _groupedSerialzedProperty) { - IEnumerable visibleProperties = group.Where(p => PropertyUtility.IsVisible(p.serializedProperty)); + IEnumerable visibleProperties = group.Where(p => PropertyUtility.IsVisible(p.showIfAttribute, p.serializedProperty)); if (!visibleProperties.Any()) { continue; } NaughtyEditorGUI.BeginBoxGroup_Layout(group.Key); - foreach (var property in visibleProperties) + foreach (var naughtyProperty in visibleProperties) { - NaughtyEditorGUI.PropertyField_Layout(property, includeChildren: true); + NaughtyEditorGUI.PropertyField_Layout(naughtyProperty, includeChildren: true); } NaughtyEditorGUI.EndBoxGroup_Layout(); @@ -134,7 +135,7 @@ protected void DrawSerializedProperties() // Draw foldout serialized properties foreach (var group in _foldoutGroupedSerializedProperty) { - IEnumerable visibleProperties = group.Where(p => PropertyUtility.IsVisible(p.serializedProperty)); + IEnumerable visibleProperties = group.Where(p => PropertyUtility.IsVisible(p.showIfAttribute, p.serializedProperty)); if (!visibleProperties.Any()) { continue; @@ -148,9 +149,9 @@ protected void DrawSerializedProperties() _foldouts[group.Key].Value = EditorGUILayout.Foldout(_foldouts[group.Key].Value, group.Key, true); if (_foldouts[group.Key].Value) { - foreach (var property in visibleProperties) + foreach (var naughtyProperty in visibleProperties) { - NaughtyEditorGUI.PropertyField_Layout(property, true); + NaughtyEditorGUI.PropertyField_Layout(naughtyProperty, true); } } } @@ -158,7 +159,7 @@ protected void DrawSerializedProperties() serializedObject.ApplyModifiedProperties(); } - protected void DrawNonSerializedFields(bool drawHeader = false) + protected virtual void DrawNonSerializedFields(bool drawHeader = false) { if (_nonSerializedFields.Any()) { @@ -177,7 +178,7 @@ protected void DrawNonSerializedFields(bool drawHeader = false) } } - protected void DrawNativeProperties(bool drawHeader = false) + protected virtual void DrawNativeProperties(bool drawHeader = false) { if (_nativeProperties.Any()) { @@ -196,7 +197,7 @@ protected void DrawNativeProperties(bool drawHeader = false) } } - protected void DrawButtons(bool drawHeader = false) + protected virtual void DrawButtons(bool drawHeader = false) { if (_methods.Any()) {