diff --git a/Assets/NaughtyAttributes/Samples/DemoScene/DemoScene.unity b/Assets/NaughtyAttributes/Samples/DemoScene/DemoScene.unity index 0a53cbda..ed6078d0 100644 --- a/Assets/NaughtyAttributes/Samples/DemoScene/DemoScene.unity +++ b/Assets/NaughtyAttributes/Samples/DemoScene/DemoScene.unity @@ -557,7 +557,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: animator0: {fileID: 1178133862} - hash0: -392453409 + hash0: -1617128887 name0: Float1 animatorParamNest1: animator1: {fileID: 1178133862} @@ -577,7 +577,7 @@ MonoBehaviour: str1: trans0: {fileID: 0} trans1: {fileID: 0} - myInt: 13 + myInt: 24 curve: serializedVersion: 2 m_Curve: diff --git a/Assets/NaughtyAttributes/Scripts/Editor/NaughtyInspector.cs b/Assets/NaughtyAttributes/Scripts/Editor/NaughtyInspector.cs index 3552d636..0b959a28 100644 --- a/Assets/NaughtyAttributes/Scripts/Editor/NaughtyInspector.cs +++ b/Assets/NaughtyAttributes/Scripts/Editor/NaughtyInspector.cs @@ -12,17 +12,17 @@ namespace NaughtyAttributes.Editor public class NaughtyInspector : UnityEditor.Editor { private List _serializedProperties = new List(); - private IEnumerable _nonSerializedFields; - private IEnumerable _nativeProperties; - private IEnumerable _methods; + private List _nonSerializedFields; + private List _nativeProperties; + private List _methods; - private IEnumerable _nonGroupedSerializedProperty; + private List _nonGroupedSerializedProperty; private SerializedProperty m_ScriptProperty; - private IEnumerable> _groupedSerialzedProperty; + private List> _groupedSerialzedProperty; - private IEnumerable> _foldoutGroupedSerializedProperty; + private List> _foldoutGroupedSerializedProperty; private Dictionary _foldouts = new Dictionary(); @@ -50,9 +50,12 @@ protected virtual void OnDisable() //cleanup memory ReorderableListPropertyDrawer.Instance.ClearCache(); - _foldoutGroupedSerializedProperty = Enumerable.Empty>(); - _groupedSerialzedProperty = Enumerable.Empty>(); - _nonGroupedSerializedProperty = Enumerable.Empty(); + _nonSerializedFields.Clear(); + _nativeProperties.Clear(); + _methods.Clear(); + _foldoutGroupedSerializedProperty.Clear(); + _groupedSerialzedProperty.Clear(); + _nonGroupedSerializedProperty.Clear(); _serializedProperties.Clear(); m_ScriptProperty = default; @@ -61,27 +64,27 @@ protected virtual void OnDisable() public virtual void Prepare() { _nonSerializedFields = ReflectionUtility.GetAllFields( - target, f => f.GetCustomAttributes(typeof(ShowNonSerializedFieldAttribute), true).Length > 0); + target, f => f.GetCustomAttributes(typeof(ShowNonSerializedFieldAttribute), true).Length > 0).ToList(); _nativeProperties = ReflectionUtility.GetAllProperties( - target, p => p.GetCustomAttributes(typeof(ShowNativePropertyAttribute), true).Length > 0); + target, p => p.GetCustomAttributes(typeof(ShowNativePropertyAttribute), true).Length > 0).ToList(); _methods = ReflectionUtility.GetAllMethods( - target, m => m.GetCustomAttributes(typeof(ButtonAttribute), true).Length > 0); + target, m => m.GetCustomAttributes(typeof(ButtonAttribute), true).Length > 0).ToList(); GetSerializedProperties(ref _serializedProperties); _anyNaughtyAttribute = _serializedProperties.Any(p => PropertyUtility.GetAttribute(p.serializedProperty) != null); - _nonGroupedSerializedProperty = GetNonGroupedProperties(_serializedProperties); + _nonGroupedSerializedProperty = GetNonGroupedProperties(_serializedProperties).ToList(); //.First(...) doesnt work for some reason because the m_Script field isnt loaded yet I assume NaughtyProperty[] mScripts = _serializedProperties.Where(p => p.serializedProperty.name.Equals("m_Script")).ToArray(); m_ScriptProperty = mScripts.Length > 0 ? mScripts[0].serializedProperty : null; - _groupedSerialzedProperty = GetGroupedProperties(_serializedProperties); + _groupedSerialzedProperty = GetGroupedProperties(_serializedProperties).ToList(); - _foldoutGroupedSerializedProperty = GetFoldoutProperties(_serializedProperties); + _foldoutGroupedSerializedProperty = GetFoldoutProperties(_serializedProperties).ToList(); _useCachedMetaAttributes = false; } diff --git a/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/AnimatorParamPropertyDrawer.cs b/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/AnimatorParamPropertyDrawer.cs index 451686b1..74204986 100644 --- a/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/AnimatorParamPropertyDrawer.cs +++ b/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/AnimatorParamPropertyDrawer.cs @@ -9,12 +9,17 @@ namespace NaughtyAttributes.Editor [CustomPropertyDrawer(typeof(AnimatorParamAttribute))] public class AnimatorParamPropertyDrawer : PropertyDrawerBase { + private AnimatorParamAttribute _cachedAnimatorParamAttribute; + private const string InvalidAnimatorControllerWarningMessage = "Target animator controller is null"; private const string InvalidTypeWarningMessage = "{0} must be an int or a string"; protected override float GetPropertyHeight_Internal(SerializedProperty property, GUIContent label) { - AnimatorParamAttribute animatorParamAttribute = PropertyUtility.GetAttribute(property); + if (_cachedAnimatorParamAttribute == null) + _cachedAnimatorParamAttribute = PropertyUtility.GetAttribute(property); + + AnimatorParamAttribute animatorParamAttribute = _cachedAnimatorParamAttribute; bool validAnimatorController = GetAnimatorController(property, animatorParamAttribute.AnimatorName) != null; bool validPropertyType = property.propertyType == SerializedPropertyType.Integer || property.propertyType == SerializedPropertyType.String; @@ -27,7 +32,10 @@ protected override void OnGUI_Internal(Rect rect, SerializedProperty property, G { EditorGUI.BeginProperty(rect, label, property); - AnimatorParamAttribute animatorParamAttribute = PropertyUtility.GetAttribute(property); + if (_cachedAnimatorParamAttribute == null) + _cachedAnimatorParamAttribute = PropertyUtility.GetAttribute(property); + + AnimatorParamAttribute animatorParamAttribute = _cachedAnimatorParamAttribute; AnimatorController animatorController = GetAnimatorController(property, animatorParamAttribute.AnimatorName); if (animatorController == null) diff --git a/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/CurveRangePropertyDrawer.cs b/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/CurveRangePropertyDrawer.cs index e7960689..995d15a5 100644 --- a/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/CurveRangePropertyDrawer.cs +++ b/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/CurveRangePropertyDrawer.cs @@ -6,6 +6,8 @@ namespace NaughtyAttributes.Editor [CustomPropertyDrawer(typeof(CurveRangeAttribute))] public class CurveRangePropertyDrawer : PropertyDrawerBase { + private CurveRangeAttribute _cachedCurveRangeAttribute; + protected override float GetPropertyHeight_Internal(SerializedProperty property, GUIContent label) { float propertyHeight = property.propertyType == SerializedPropertyType.AnimationCurve @@ -27,7 +29,10 @@ protected override void OnGUI_Internal(Rect rect, SerializedProperty property, G return; } - var attribute = PropertyUtility.GetAttribute(property); + if (_cachedCurveRangeAttribute == null) + _cachedCurveRangeAttribute = PropertyUtility.GetAttribute(property); + + var attribute = _cachedCurveRangeAttribute; EditorGUI.CurveField( rect, diff --git a/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/ProgressBarPropertyDrawer.cs b/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/ProgressBarPropertyDrawer.cs index f1e2787e..62512832 100644 --- a/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/ProgressBarPropertyDrawer.cs +++ b/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/ProgressBarPropertyDrawer.cs @@ -7,9 +7,14 @@ namespace NaughtyAttributes.Editor [CustomPropertyDrawer(typeof(ProgressBarAttribute))] public class ProgressBarPropertyDrawer : PropertyDrawerBase { + private ProgressBarAttribute _cachedProgressBarAttribute; + protected override float GetPropertyHeight_Internal(SerializedProperty property, GUIContent label) { - ProgressBarAttribute progressBarAttribute = PropertyUtility.GetAttribute(property); + if (_cachedProgressBarAttribute == null) + _cachedProgressBarAttribute = PropertyUtility.GetAttribute(property); + + ProgressBarAttribute progressBarAttribute = _cachedProgressBarAttribute; var maxValue = GetMaxValue(property, progressBarAttribute); return IsNumber(property) && IsNumber(maxValue) @@ -28,7 +33,10 @@ protected override void OnGUI_Internal(Rect rect, SerializedProperty property, G return; } - ProgressBarAttribute progressBarAttribute = PropertyUtility.GetAttribute(property); + if (_cachedProgressBarAttribute == null) + _cachedProgressBarAttribute = PropertyUtility.GetAttribute(property); + + ProgressBarAttribute progressBarAttribute = _cachedProgressBarAttribute; var value = property.propertyType == SerializedPropertyType.Integer ? property.intValue : property.floatValue; var valueFormatted = property.propertyType == SerializedPropertyType.Integer ? value.ToString() : string.Format("{0:0.00}", value); var maxValue = GetMaxValue(property, progressBarAttribute); diff --git a/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/PropertyDrawerBase.cs b/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/PropertyDrawerBase.cs index 4c5888de..d460a6cf 100644 --- a/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/PropertyDrawerBase.cs +++ b/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/PropertyDrawerBase.cs @@ -5,6 +5,8 @@ namespace NaughtyAttributes.Editor { public abstract class PropertyDrawerBase : PropertyDrawer { + private SpecialCaseDrawerAttribute _cachedSpecialCaseDrawerAttribute; + public sealed override void OnGUI(Rect rect, SerializedProperty property, GUIContent label) { // Check if visible @@ -57,7 +59,10 @@ protected virtual float GetPropertyHeight_Internal(SerializedProperty property, protected float GetPropertyHeight(SerializedProperty property) { - SpecialCaseDrawerAttribute specialCaseAttribute = PropertyUtility.GetAttribute(property); + if (_cachedSpecialCaseDrawerAttribute == null) + _cachedSpecialCaseDrawerAttribute = PropertyUtility.GetAttribute(property); + + SpecialCaseDrawerAttribute specialCaseAttribute = _cachedSpecialCaseDrawerAttribute; if (specialCaseAttribute != null) { return specialCaseAttribute.GetDrawer().GetPropertyHeight(property); diff --git a/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/ShowAssetPreviewPropertyDrawer.cs b/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/ShowAssetPreviewPropertyDrawer.cs index 0d0fe9be..d0bd8521 100644 --- a/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/ShowAssetPreviewPropertyDrawer.cs +++ b/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/ShowAssetPreviewPropertyDrawer.cs @@ -6,6 +6,8 @@ namespace NaughtyAttributes.Editor [CustomPropertyDrawer(typeof(ShowAssetPreviewAttribute))] public class ShowAssetPreviewPropertyDrawer : PropertyDrawerBase { + private ShowAssetPreviewAttribute _cachedShowAssetPreviewAttribute; + protected override float GetPropertyHeight_Internal(SerializedProperty property, GUIContent label) { if (property.propertyType == SerializedPropertyType.ObjectReference) @@ -93,7 +95,11 @@ private Vector2 GetAssetPreviewSize(SerializedProperty property) int targetWidth = ShowAssetPreviewAttribute.DefaultWidth; int targetHeight = ShowAssetPreviewAttribute.DefaultHeight; - ShowAssetPreviewAttribute showAssetPreviewAttribute = PropertyUtility.GetAttribute(property); + if (_cachedShowAssetPreviewAttribute == null) + _cachedShowAssetPreviewAttribute = + PropertyUtility.GetAttribute(property); + + ShowAssetPreviewAttribute showAssetPreviewAttribute = _cachedShowAssetPreviewAttribute; if (showAssetPreviewAttribute != null) { targetWidth = showAssetPreviewAttribute.Width; diff --git a/Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/MaxValuePropertyValidator.cs b/Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/MaxValuePropertyValidator.cs index 16ab419b..2e10ba5b 100644 --- a/Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/MaxValuePropertyValidator.cs +++ b/Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/MaxValuePropertyValidator.cs @@ -5,9 +5,14 @@ namespace NaughtyAttributes.Editor { public class MaxValuePropertyValidator : PropertyValidatorBase { + private MaxValueAttribute _cachedMaxValueAttribute; + public override void ValidateProperty(SerializedProperty property) { - MaxValueAttribute maxValueAttribute = PropertyUtility.GetAttribute(property); + if (_cachedMaxValueAttribute == null) + _cachedMaxValueAttribute = PropertyUtility.GetAttribute(property); + + MaxValueAttribute maxValueAttribute = _cachedMaxValueAttribute; if (property.propertyType == SerializedPropertyType.Integer) { diff --git a/Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/MinValuePropertyValidator.cs b/Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/MinValuePropertyValidator.cs index 69cd7299..5338a401 100644 --- a/Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/MinValuePropertyValidator.cs +++ b/Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/MinValuePropertyValidator.cs @@ -5,9 +5,14 @@ namespace NaughtyAttributes.Editor { public class MinValuePropertyValidator : PropertyValidatorBase { + private MinValueAttribute _cachedMinValueAttribute; + public override void ValidateProperty(SerializedProperty property) { - MinValueAttribute minValueAttribute = PropertyUtility.GetAttribute(property); + if (_cachedMinValueAttribute == null) + _cachedMinValueAttribute = PropertyUtility.GetAttribute(property); + + MinValueAttribute minValueAttribute = _cachedMinValueAttribute; if (property.propertyType == SerializedPropertyType.Integer) { diff --git a/Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/RequiredPropertyValidator.cs b/Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/RequiredPropertyValidator.cs index b1d15eb8..e76571a9 100644 --- a/Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/RequiredPropertyValidator.cs +++ b/Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/RequiredPropertyValidator.cs @@ -4,9 +4,14 @@ namespace NaughtyAttributes.Editor { public class RequiredPropertyValidator : PropertyValidatorBase { + private RequiredAttribute _cachedRequiredAttribute; + public override void ValidateProperty(SerializedProperty property) { - RequiredAttribute requiredAttribute = PropertyUtility.GetAttribute(property); + if (_cachedRequiredAttribute == null) + _cachedRequiredAttribute = PropertyUtility.GetAttribute(property); + + RequiredAttribute requiredAttribute = _cachedRequiredAttribute; if (property.propertyType == SerializedPropertyType.ObjectReference) { diff --git a/Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/ValidateInputPropertyValidator.cs b/Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/ValidateInputPropertyValidator.cs index 96277bb7..c1a431b2 100644 --- a/Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/ValidateInputPropertyValidator.cs +++ b/Assets/NaughtyAttributes/Scripts/Editor/PropertyValidators/ValidateInputPropertyValidator.cs @@ -6,9 +6,14 @@ namespace NaughtyAttributes.Editor { public class ValidateInputPropertyValidator : PropertyValidatorBase { + private ValidateInputAttribute _cachedValidateInputAttribute; + public override void ValidateProperty(SerializedProperty property) { - ValidateInputAttribute validateInputAttribute = PropertyUtility.GetAttribute(property); + if (_cachedValidateInputAttribute == null) + _cachedValidateInputAttribute = PropertyUtility.GetAttribute(property); + + ValidateInputAttribute validateInputAttribute = _cachedValidateInputAttribute; object target = PropertyUtility.GetTargetObjectWithProperty(property); MethodInfo validationCallback = ReflectionUtility.GetMethod(target, validateInputAttribute.CallbackName); diff --git a/Assets/NaughtyAttributes/Scripts/Editor/Utility/PropertyUtility.cs b/Assets/NaughtyAttributes/Scripts/Editor/Utility/PropertyUtility.cs index 4f7dc6f1..f73796e7 100644 --- a/Assets/NaughtyAttributes/Scripts/Editor/Utility/PropertyUtility.cs +++ b/Assets/NaughtyAttributes/Scripts/Editor/Utility/PropertyUtility.cs @@ -11,6 +11,8 @@ public static class PropertyUtility { public static T GetAttribute(SerializedProperty property) where T : class { + //Debug.Log("waste of time"); + T[] attributes = GetAttributes(property); return (attributes.Length > 0) ? attributes[0] : null; }