Skip to content

Commit

Permalink
dbrizov#133 GetLabel Attribute caching
Browse files Browse the repository at this point in the history
  • Loading branch information
niggo1243 committed Sep 10, 2021
1 parent 92c907b commit 4f5a6b1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
10 changes: 5 additions & 5 deletions Assets/NaughtyAttributes/Scripts/Editor/NaughtyInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,16 @@ protected virtual void DrawSerializedProperties()
{
continue;
}

NaughtyEditorGUI.BeginBoxGroup_Layout(group.Key);
foreach (var naughtyProperty in visibleProperties)
{
NaughtyEditorGUI.PropertyField_Layout(naughtyProperty, includeChildren: true);
}

NaughtyEditorGUI.EndBoxGroup_Layout();
}

// Draw foldout serialized properties
foreach (var group in _foldoutGroupedSerializedProperty)
{
Expand All @@ -162,12 +162,12 @@ protected virtual void DrawSerializedProperties()
{
continue;
}

if (!_foldouts.ContainsKey(group.Key))
{
_foldouts[group.Key] = new SavedBool($"{target.GetInstanceID()}.{group.Key}", false);
}

_foldouts[group.Key].Value = EditorGUILayout.Foldout(_foldouts[group.Key].Value, group.Key, true);
if (_foldouts[group.Key].Value)
{
Expand Down
7 changes: 4 additions & 3 deletions Assets/NaughtyAttributes/Scripts/Editor/NaughtyProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ namespace NaughtyAttributes.Editor
public class NaughtyProperty
{
public SerializedProperty serializedProperty;

public LabelAttribute labelAttribute;

public SpecialCaseDrawerAttribute specialCaseDrawerAttribute;

public ShowIfAttributeBase showIfAttribute;

public EnableIfAttributeBase enableIfAttribute;

public ReadOnlyAttribute readOnlyAttribute;

public ValidatorAttribute[] validatorAttributes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static void PropertyField_Implementation(Rect rect, NaughtyProperty naug

using (new EditorGUI.DisabledScope(disabled: !enabled))
{
propertyFieldFunction.Invoke(rect, naughtyProperty, PropertyUtility.GetLabel(naughtyProperty.serializedProperty), includeChildren);
propertyFieldFunction.Invoke(rect, naughtyProperty, PropertyUtility.GetLabel(naughtyProperty.labelAttribute, naughtyProperty.serializedProperty), includeChildren);
}

// Call OnValueChanged callbacks
Expand Down
19 changes: 13 additions & 6 deletions Assets/NaughtyAttributes/Scripts/Editor/Utility/PropertyUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,28 @@ public static NaughtyProperty CreateNaughtyProperty(SerializedProperty serialize
NaughtyProperty naughtyProperty = new NaughtyProperty();
naughtyProperty.serializedProperty = serializedProperty;

naughtyProperty.readOnlyAttribute = PropertyUtility.GetAttribute<ReadOnlyAttribute>(naughtyProperty.serializedProperty);
naughtyProperty.enableIfAttribute = PropertyUtility.GetAttribute<EnableIfAttributeBase>(naughtyProperty.serializedProperty);
naughtyProperty.readOnlyAttribute = PropertyUtility.GetAttribute<ReadOnlyAttribute>(serializedProperty);
naughtyProperty.enableIfAttribute = PropertyUtility.GetAttribute<EnableIfAttributeBase>(serializedProperty);

naughtyProperty.showIfAttribute = PropertyUtility.GetAttribute<ShowIfAttributeBase>(naughtyProperty.serializedProperty);
naughtyProperty.validatorAttributes = PropertyUtility.GetAttributes<ValidatorAttribute>(naughtyProperty.serializedProperty);
naughtyProperty.showIfAttribute = PropertyUtility.GetAttribute<ShowIfAttributeBase>(serializedProperty);
naughtyProperty.validatorAttributes = PropertyUtility.GetAttributes<ValidatorAttribute>(serializedProperty);

naughtyProperty.labelAttribute = PropertyUtility.GetAttribute<LabelAttribute>(serializedProperty);

naughtyProperty.specialCaseDrawerAttribute =
PropertyUtility.GetAttribute<SpecialCaseDrawerAttribute>(naughtyProperty.serializedProperty);
PropertyUtility.GetAttribute<SpecialCaseDrawerAttribute>(serializedProperty);

return naughtyProperty;
}

public static GUIContent GetLabel(SerializedProperty property)
{
LabelAttribute labelAttribute = GetAttribute<LabelAttribute>(property);
return GetLabel(labelAttribute, property);
}

public static GUIContent GetLabel(LabelAttribute labelAttribute, SerializedProperty property)
{
string labelText = (labelAttribute == null)
? property.displayName
: labelAttribute.Label;
Expand Down Expand Up @@ -155,7 +162,7 @@ public static bool IsVisible(ShowIfAttributeBase showIfAttribute, SerializedProp
{
return true;
}

object target = GetTargetObjectWithProperty(property);

// deal with enum conditions
Expand Down

0 comments on commit 4f5a6b1

Please sign in to comment.