diff --git a/Assets/NaughtyAttributes/Samples/DemoScene/DemoScene.unity b/Assets/NaughtyAttributes/Samples/DemoScene/DemoScene.unity index d4be8e1a..6aa74d6d 100644 --- a/Assets/NaughtyAttributes/Samples/DemoScene/DemoScene.unity +++ b/Assets/NaughtyAttributes/Samples/DemoScene/DemoScene.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.44657874, g: 0.49641258, b: 0.5748172, a: 1} + m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -200,24 +200,33 @@ MonoBehaviour: m_EditorClassIdentifier: enable1: 0 enable2: 0 - enum1: 0 + enum1: 2 + enum2: 3 enableIfAll: enableIfAny: enableIfEnum: + enableIfEnumFlag: + enableIfEnumFlagMulti: nest1: enable1: 1 enable2: 0 enum1: 0 + enum2: 0 enableIfAll: 1 enableIfAny: 2 enableIfEnum: 0 + enableIfEnumFlag: 0 + enableIfEnumFlagMulti: 0 nest2: enable1: 1 enable2: 1 enum1: 0 + enum2: 0 enableIfAll: {x: 0.25, y: 0.75} enableIfAny: {x: 0.25, y: 0.75} enableIfEnum: {x: 0.25, y: 0.75} + enableIfEnumFlag: {x: 0, y: 0} + enableIfEnumFlagMulti: {x: 0, y: 0} --- !u!114 &114650326 MonoBehaviour: m_ObjectHideFlags: 0 @@ -233,23 +242,32 @@ MonoBehaviour: disable1: 0 disable2: 0 enum1: 0 + enum2: 0 disableIfAll: disableIfAny: disableIfEnum: + disableIfEnumFlag: + disableIfEnumFlagMulti: nest1: disable1: 1 disable2: 0 enum1: 0 + enum2: 0 disableIfAll: 1 disableIfAny: 2 disableIfEnum: 3 + disableIfEnumFlag: 0 + disableIfEnumFlagMulti: 0 nest2: disable1: 1 disable2: 1 enum1: 0 + enum2: 0 enableIfAll: {x: 0.25, y: 0.75} enableIfAny: {x: 0.25, y: 0.75} enableIfEnum: {x: 0.25, y: 0.75} + disableIfEnumFlag: {x: 0, y: 0} + disableIfEnumFlagMulti: {x: 0, y: 0} --- !u!1 &155697335 GameObject: m_ObjectHideFlags: 0 @@ -293,11 +311,11 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e0cc8a31c22090847b75538c0ed2d2fc, type: 3} m_Name: m_EditorClassIdentifier: - inputAxis0: + inputAxis0: Fire1 nest1: - inputAxis1: Horizontal + inputAxis1: Vertical nest2: - inputAxis2: Vertical + inputAxis2: Fire2 --- !u!1 &237121640 GameObject: m_ObjectHideFlags: 0 @@ -490,11 +508,273 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: fd67fbde6acdd6a44944f12e507067c5, type: 3} m_Name: m_EditorClassIdentifier: - minMaxSlider0: {x: 0, y: 0.5} + minMaxSlider0: {x: 0.10512249, y: 0.5} nest1: - minMaxSlider1: {x: 0.25, y: 0.75} + minMaxSlider1: {x: 0.25, y: 0.5771715} nest2: minMaxSlider2: {x: 6, y: 11} +--- !u!1 &645779700 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 645779701} + - component: {fileID: 645779702} + m_Layer: 0 + m_Name: HugeMixPerformanceTest + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &645779701 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 645779700} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 1148579784} + m_RootOrder: 33 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &645779702 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 645779700} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9d0844cc6e62fe54393612902562c4e2, type: 3} + m_Name: + m_EditorClassIdentifier: + animator0: {fileID: 1178133862} + hash0: -1617128887 + name0: Float1 + animatorParamNest1: + animator1: {fileID: 1178133862} + animatorController1: {fileID: 0} + hash1: 726565755 + name1: Float1 + hashController1: 0 + nameController1: + nest2: + animator2: {fileID: 1178133862} + animatorController2: {fileID: 0} + hash1: 0 + name1: Trigger0 + hashController2: 0 + nameController2: + int0: 25 + int1: 0 + float0: 0 + float1: 0 + slider0: {x: 0, y: 0} + slider1: {x: 0, y: 0} + str0: dfgdfg + str1: + trans0: {fileID: 0} + trans1: {fileID: 0} + myInt: 24 + curve: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: -1 + value: -1 + inSlope: 0 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 1 + value: 1 + inSlope: 2 + outSlope: 2 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + curve1: + serializedVersion: 2 + m_Curve: [] + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + curve2: + serializedVersion: 2 + m_Curve: [] + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + curveRangeNest1: + curve: + serializedVersion: 2 + m_Curve: [] + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + curveRangeNest2: + curve: + serializedVersion: 2 + m_Curve: [] + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + disableIf1: 0 + disableIf2: 0 + disableIfEnum1: 2 + disableIfEnum2: 0 + disableIfAll: + disableIfAny: + disableIfEnum: + disableIfEnumFlag: + disableIfEnumFlagMulti: + disableIfNest1: + disable1: 0 + disable2: 0 + enum1: 0 + enum2: 0 + disableIfAll: 1 + disableIfAny: 2 + disableIfEnum: 3 + disableIfEnumFlag: 0 + disableIfEnumFlagMulti: 0 + nest2: + disable1: 0 + disable2: 0 + enum1: 0 + enum2: 0 + enableIfAll: {x: 0.25, y: 0.75} + enableIfAny: {x: 0.25, y: 0.75} + enableIfEnum: {x: 0.25, y: 0.75} + disableIfEnumFlag: {x: 0, y: 0} + disableIfEnumFlagMulti: {x: 0, y: 0} + dropDownIntValue: 1 + dropdownNest1: + stringValue: + nest2: + vectorValue: {x: 0, y: 0, z: 0} + enable1: 0 + enable2: 1 + enableIfEnum1: 1 + enableIfEnum2: 10 + enableIfAll: + enableIfAny: + enableIfEnum: + enableIfEnumFlag: + enableIfEnumFlagMulti: + enableIfNest1: + enable1: 0 + enable2: 0 + enum1: 0 + enum2: 0 + enableIfAll: 0 + enableIfAny: 0 + enableIfEnum: 0 + enableIfEnumFlag: 0 + enableIfEnumFlagMulti: 0 + nest2: + enable1: 0 + enable2: 0 + enum1: 0 + enum2: 0 + enableIfAll: {x: 0.25, y: 0.75} + enableIfAny: {x: 0.25, y: 0.75} + enableIfEnum: {x: 0.25, y: 0.75} + enableIfEnumFlag: {x: 0, y: 0} + enableIfEnumFlagMulti: {x: 0, y: 0} + enumFlagsTest0: 1 + enumFlagsNest1: + flags1: 0 + nest2: + flags2: 0 + obj0: {fileID: 0} + expandableScriptableObjectNest1: + obj1: {fileID: 0} + nest2: + obj2: {fileID: 0} + foldoutTestInt0: 27 + foldoutTestInt1: 0 + foldoutTestFloat0: 0 + foldoutTestFloat1: 0 + foldoutTestSlider0: {x: 0.4172527, y: 0.8947535} + foldoutTestSlider1: {x: 0, y: 1} + foldoutTestStr0: + foldoutTestStr1: + foldoutTestTrans0: {fileID: 0} + foldoutTestTrans1: {fileID: 0} + hide1: 0 + hide2: 0 + hideIfEnum1: 1 + hideIfEnum2: 0 + hideIfAll: + hideIfAny: + hideIfEnum: + hideIfEnumFlag: + hideIfEnumFlagMulti: + hideIfNest1: + hide1: 0 + hide2: 0 + enum1: 0 + enum2: 0 + hideIfAll: 0 + hideIfAny: 0 + hideIfEnum: 0 + hideIfEnumFlag: 0 + hideIfEnumFlagMulti: 0 + nest2: + hide1: 0 + hide2: 0 + enum1: 0 + enum2: 0 + hideIfAll: {x: 0.25, y: 0.75} + hideIfAny: {x: 0.25, y: 0.75} + hideIfEnum: {x: 0.25, y: 0.75} + hideIfEnumFlag: {x: 0, y: 0} + hideIfEnumFlagMulti: {x: 0, y: 0} + showIf1: 1 + showIf2: 0 + showIfEnum1: 1 + showIfEnum2: 1 + showIfAll: + showIfAny: + showIfEnum: + showIfEnumFlag: + showIfEnumFlagMulti: + showIfNest1: + show1: 0 + show2: 0 + enum1: 0 + enum2: 0 + showIfAll: 0 + showIfAny: 0 + showIfEnum: 0 + showIfEnumFlag: 0 + showIfEnumFlagMulti: 0 + nest2: + show1: 0 + show2: 0 + enum1: 0 + enum2: 0 + showIfAll: {x: 0.25, y: 0.75} + showIfAny: {x: 0.25, y: 0.75} + showIfEnum: {x: 0.25, y: 0.75} + showIfEnumFlag: {x: 0, y: 0} + showIfEnumFlagMulti: {x: 0, y: 0} --- !u!1 &706445688 GameObject: m_ObjectHideFlags: 0 @@ -538,8 +818,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 9c928ea15ae74a44089beb2e534c1a35, type: 3} m_Name: m_EditorClassIdentifier: - layerName: Default - layerIndex: 4 --- !u!1 &732714203 GameObject: m_ObjectHideFlags: 0 @@ -767,7 +1045,7 @@ MonoBehaviour: nest2: stamina: 75 elixir: 50 - maxElixir: 100 + maxElixir: 71 --- !u!1 &993534225 GameObject: m_ObjectHideFlags: 0 @@ -926,6 +1204,8 @@ Transform: - {fileID: 1706612702} - {fileID: 369789277} - {fileID: 1463483878} + - {fileID: 1468344835} + - {fileID: 645779701} m_Father: {fileID: 0} m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -974,16 +1254,27 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: animator0: {fileID: 1178133862} - hash0: 1943738498 + animatorController0: {fileID: 9100000, guid: 63ee86efd213bf34285c95f33e79dc6c, type: 2} + hash0: -392453409 name0: Float0 + hashController0: 726565755 + nameController0: Trigger1 nest1: animator1: {fileID: 1178133862} - hash1: 726565755 + animatorController1: {fileID: 9100000, guid: 63ee86efd213bf34285c95f33e79dc6c, + type: 2} + hash1: 1548334061 name1: Float0 + hashController1: 1548334061 + nameController1: Float1 nest2: animator2: {fileID: 1178133862} + animatorController2: {fileID: 9100000, guid: 63ee86efd213bf34285c95f33e79dc6c, + type: 2} hash1: -392453409 name1: Trigger0 + hashController2: -392453409 + nameController2: Trigger1 --- !u!95 &1178133862 Animator: serializedVersion: 3 @@ -1209,9 +1500,9 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 8bcc0d5613b48fb43bd36c9d37e99900, type: 3} m_Name: m_EditorClassIdentifier: - tag0: + tag0: Finish nest1: - tag1: MainCamera + tag1: EditorOnly nest2: tag2: Player --- !u!1 &1444377589 @@ -1350,11 +1641,45 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 94adafcfe59aa344c9b5596b2cc6ecd0, type: 3} m_Name: m_EditorClassIdentifier: - int0: 0 + int0: 2 nest1: int1: 0 nest2: int2: 0 + inheritedNest: + int1: 0 + nest2: + int2: 0 +--- !u!1 &1468344834 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1468344835} + m_Layer: 0 + m_Name: ===== Mixxed Attributes ===== + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1468344835 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1468344834} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 1148579784} + m_RootOrder: 32 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1524906390 GameObject: m_ObjectHideFlags: 0 @@ -1402,23 +1727,32 @@ MonoBehaviour: show1: 0 show2: 0 enum1: 0 + enum2: 0 showIfAll: showIfAny: showIfEnum: + showIfEnumFlag: + showIfEnumFlagMulti: nest1: show1: 1 show2: 0 enum1: 0 + enum2: 0 showIfAll: 0 showIfAny: 0 showIfEnum: 0 + showIfEnumFlag: 0 + showIfEnumFlagMulti: 0 nest2: show1: 1 show2: 1 enum1: 0 + enum2: 0 showIfAll: {x: 0.25, y: 0.75} showIfAny: {x: 0.25, y: 0.75} showIfEnum: {x: 0.25, y: 0.75} + showIfEnumFlag: {x: 0, y: 0} + showIfEnumFlagMulti: {x: 0, y: 0} --- !u!114 &1524906393 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1434,23 +1768,32 @@ MonoBehaviour: hide1: 0 hide2: 0 enum1: 0 + enum2: 0 hideIfAll: hideIfAny: hideIfEnum: + hideIfEnumFlag: + hideIfEnumFlagMulti: nest1: hide1: 1 hide2: 0 enum1: 0 + enum2: 0 hideIfAll: 0 hideIfAny: 0 hideIfEnum: 0 + hideIfEnumFlag: 0 + hideIfEnumFlagMulti: 0 nest2: hide1: 1 hide2: 1 enum1: 0 + enum2: 0 hideIfAll: {x: 0.25, y: 0.75} hideIfAny: {x: 0.25, y: 0.75} hideIfEnum: {x: 0.25, y: 0.75} + hideIfEnumFlag: {x: 0, y: 0} + hideIfEnumFlagMulti: {x: 0, y: 0} --- !u!1 &1552114399 GameObject: m_ObjectHideFlags: 0 @@ -1494,11 +1837,11 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 0dcb08e489c17644e9eacaa1ec5fe781, type: 3} m_Name: m_EditorClassIdentifier: - normal: 0 + normal: 37 nest1: - warning: 0 + warning: 37 nest2: - error: 0 + error: 70 --- !u!1 &1591883662 GameObject: m_ObjectHideFlags: 0 @@ -1787,22 +2130,24 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c93fde7cd79390148ac576c3a159a77b, type: 3} m_Name: m_EditorClassIdentifier: - intArray: 020000000300000001000000 + intArray: 010000000300000002000000 vectorList: - - {x: 2, y: 2, z: 2} - {x: 3, y: 3, z: 3} + - {x: 2, y: 2, z: 2} - {x: 1, y: 1, z: 1} structList: - - Int: 2 - Float: 2 - Vector: {x: 2, y: 2, z: 2} - Int: 3 Float: 3 Vector: {x: 3, y: 3, z: 3} - Int: 1 - Float: 1 + Float: 1.96 Vector: {x: 1, y: 1, z: 1} - gameObjectsList: [] + - Int: 2 + Float: 2 + Vector: {x: 2, y: 2, z: 2} + gameObjectsList: + - {fileID: 0} + - {fileID: 0} transformsList: [] monoBehavioursList: [] --- !u!1 &1784643784 @@ -1848,13 +2193,13 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 3920f5ea384951b4990e4d9e8032d12e, type: 3} m_Name: m_EditorClassIdentifier: - int0: 0 + int0: 27 int1: 0 - float0: 0 + float0: 2.23 float1: 0 - slider0: {x: 0.25, y: 0.75} + slider0: {x: 0.33104458, y: 0.75} slider1: {x: 0.25, y: 0.75} - str0: + str0: gg str1: trans0: {fileID: 0} trans1: {fileID: 0} diff --git a/Assets/NaughtyAttributes/Samples/DemoScene/TestAssets/NaughtyScriptableObject.asset b/Assets/NaughtyAttributes/Samples/DemoScene/TestAssets/NaughtyScriptableObject.asset index ce97939e..673d2a6b 100644 --- a/Assets/NaughtyAttributes/Samples/DemoScene/TestAssets/NaughtyScriptableObject.asset +++ b/Assets/NaughtyAttributes/Samples/DemoScene/TestAssets/NaughtyScriptableObject.asset @@ -16,3 +16,6 @@ MonoBehaviour: - {fileID: 11400000, guid: 149474eb879a6a641b560ca17d48712f, type: 2} - {fileID: 11400000, guid: ca97c330d5c96794aa4df848d63f836b, type: 2} - {fileID: 0} + animatorController0: {fileID: 9100000, guid: 63ee86efd213bf34285c95f33e79dc6c, type: 2} + hashController0: -392453409 + nameController0: Trigger1 diff --git a/Assets/NaughtyAttributes/Scripts/Editor/NaughtyInspector.cs b/Assets/NaughtyAttributes/Scripts/Editor/NaughtyInspector.cs index f1bcbb67..0b959a28 100644 --- a/Assets/NaughtyAttributes/Scripts/Editor/NaughtyInspector.cs +++ b/Assets/NaughtyAttributes/Scripts/Editor/NaughtyInspector.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; + using UnityEditor; using UnityEngine; @@ -10,35 +11,89 @@ namespace NaughtyAttributes.Editor [CustomEditor(typeof(UnityEngine.Object), true)] public class NaughtyInspector : UnityEditor.Editor { - private List _serializedProperties = new List(); - private IEnumerable _nonSerializedFields; - private IEnumerable _nativeProperties; - private IEnumerable _methods; + private List _serializedProperties = new List(); + private List _nonSerializedFields; + private List _nativeProperties; + private List _methods; + + private List _nonGroupedSerializedProperty; + + private SerializedProperty m_ScriptProperty; + + private List> _groupedSerialzedProperty; + + private List> _foldoutGroupedSerializedProperty; + private Dictionary _foldouts = new Dictionary(); + private bool _anyNaughtyAttribute; + private bool _useCachedMetaAttributes; + private bool _changeDetected; + protected virtual void OnEnable() { - _nonSerializedFields = ReflectionUtility.GetAllFields( - target, f => f.GetCustomAttributes(typeof(ShowNonSerializedFieldAttribute), true).Length > 0); - - _nativeProperties = ReflectionUtility.GetAllProperties( - target, p => p.GetCustomAttributes(typeof(ShowNativePropertyAttribute), true).Length > 0); - - _methods = ReflectionUtility.GetAllMethods( - target, m => m.GetCustomAttributes(typeof(ButtonAttribute), true).Length > 0); + /* + * TODO: + * OnEnable is called for all monos and scriptable objects, + * which eats some one time perf after compilation and also takes some memory (although not noticeable) + * any other way to trigger this like via a custom editor/ window with on focus?? + * + * Selection.selectionChanged += ???? + * Base Mono and SO scripts that handle this?? + */ + + this.Prepare(); } protected virtual void OnDisable() { + //cleanup memory ReorderableListPropertyDrawer.Instance.ClearCache(); + + _nonSerializedFields.Clear(); + _nativeProperties.Clear(); + _methods.Clear(); + _foldoutGroupedSerializedProperty.Clear(); + _groupedSerialzedProperty.Clear(); + _nonGroupedSerializedProperty.Clear(); + _serializedProperties.Clear(); + + m_ScriptProperty = default; } - public override void OnInspectorGUI() + public virtual void Prepare() { + _nonSerializedFields = ReflectionUtility.GetAllFields( + target, f => f.GetCustomAttributes(typeof(ShowNonSerializedFieldAttribute), true).Length > 0).ToList(); + + _nativeProperties = ReflectionUtility.GetAllProperties( + target, p => p.GetCustomAttributes(typeof(ShowNativePropertyAttribute), true).Length > 0).ToList(); + + _methods = ReflectionUtility.GetAllMethods( + 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).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).ToList(); - bool anyNaughtyAttribute = _serializedProperties.Any(p => PropertyUtility.GetAttribute(p) != null); - if (!anyNaughtyAttribute) + _foldoutGroupedSerializedProperty = GetFoldoutProperties(_serializedProperties).ToList(); + + _useCachedMetaAttributes = false; + } + + public override void OnInspectorGUI() + { + _changeDetected = false; + + if (!_anyNaughtyAttribute) { DrawDefaultInspector(); } @@ -50,82 +105,116 @@ public override void OnInspectorGUI() DrawNonSerializedFields(); DrawNativeProperties(); DrawButtons(); - } - protected void GetSerializedProperties(ref List outSerializedProperties) + _useCachedMetaAttributes = !_changeDetected; + } + + protected virtual void GetSerializedProperties(ref List outSerializedProperties) { outSerializedProperties.Clear(); + outSerializedProperties.TrimExcess(); + using (var iterator = serializedObject.GetIterator()) { if (iterator.NextVisible(true)) { do { - outSerializedProperties.Add(serializedObject.FindProperty(iterator.name)); + outSerializedProperties.Add( + PropertyUtility.CreateNaughtyProperty( + serializedObject.FindProperty(iterator.name))); } while (iterator.NextVisible(false)); } } } - protected void DrawSerializedProperties() + protected virtual void DrawSerializedProperties() { serializedObject.Update(); - // Draw non-grouped serialized properties - foreach (var property in GetNonGroupedProperties(_serializedProperties)) + if (m_ScriptProperty != null) { - if (property.name.Equals("m_Script", System.StringComparison.Ordinal)) + using (new EditorGUI.DisabledScope(disabled: true)) { - using (new EditorGUI.DisabledScope(disabled: true)) - { - EditorGUILayout.PropertyField(property); - } + EditorGUILayout.PropertyField(m_ScriptProperty); } - else + } + + // Draw non-grouped serialized properties + foreach (var naughtyProperty in _nonGroupedSerializedProperty) + { + if (!_useCachedMetaAttributes) { - NaughtyEditorGUI.PropertyField_Layout(property, includeChildren: true); + naughtyProperty.cachedIsVisible = PropertyUtility.IsVisible(naughtyProperty.showIfAttribute, + naughtyProperty.serializedProperty); + + naughtyProperty.cachedIsEnabled = PropertyUtility.IsEnabled(naughtyProperty.readOnlyAttribute, naughtyProperty.enableIfAttribute, + naughtyProperty.serializedProperty); } + + _changeDetected |= NaughtyEditorGUI.PropertyField_Layout(naughtyProperty, includeChildren: true); } // Draw grouped serialized properties - foreach (var group in GetGroupedProperties(_serializedProperties)) + foreach (var group in _groupedSerialzedProperty) { - IEnumerable visibleProperties = group.Where(p => PropertyUtility.IsVisible(p)); + IEnumerable visibleProperties = + _useCachedMetaAttributes + ? group.Where(p => p.cachedIsVisible) + : group.Where(p => + { + p.cachedIsEnabled = PropertyUtility.IsEnabled(p.readOnlyAttribute, p.enableIfAttribute, + p.serializedProperty); + + return p.cachedIsVisible = + 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); + _changeDetected |= NaughtyEditorGUI.PropertyField_Layout(naughtyProperty, includeChildren: true); } - NaughtyEditorGUI.EndBoxGroup_Layout(); } - + // Draw foldout serialized properties - foreach (var group in GetFoldoutProperties(_serializedProperties)) + foreach (var group in _foldoutGroupedSerializedProperty) { - IEnumerable visibleProperties = group.Where(p => PropertyUtility.IsVisible(p)); + IEnumerable visibleProperties = + _useCachedMetaAttributes + ? group.Where(p => p.cachedIsVisible) + : group.Where(p => + { + p.cachedIsEnabled = PropertyUtility.IsEnabled(p.readOnlyAttribute, p.enableIfAttribute, + p.serializedProperty); + + return p.cachedIsVisible = + PropertyUtility.IsVisible(p.showIfAttribute, p.serializedProperty); + }); + if (!visibleProperties.Any()) { 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) { - foreach (var property in visibleProperties) + foreach (var naughtyProperty in visibleProperties) { - NaughtyEditorGUI.PropertyField_Layout(property, true); + _changeDetected |= NaughtyEditorGUI.PropertyField_Layout(naughtyProperty, true); } } } @@ -133,7 +222,7 @@ protected void DrawSerializedProperties() serializedObject.ApplyModifiedProperties(); } - protected void DrawNonSerializedFields(bool drawHeader = false) + protected virtual void DrawNonSerializedFields(bool drawHeader = false) { if (_nonSerializedFields.Any()) { @@ -152,7 +241,7 @@ protected void DrawNonSerializedFields(bool drawHeader = false) } } - protected void DrawNativeProperties(bool drawHeader = false) + protected virtual void DrawNativeProperties(bool drawHeader = false) { if (_nativeProperties.Any()) { @@ -171,7 +260,7 @@ protected void DrawNativeProperties(bool drawHeader = false) } } - protected void DrawButtons(bool drawHeader = false) + protected virtual void DrawButtons(bool drawHeader = false) { if (_methods.Any()) { @@ -190,23 +279,23 @@ protected void DrawButtons(bool drawHeader = false) } } - private static IEnumerable GetNonGroupedProperties(IEnumerable properties) + private static IEnumerable GetNonGroupedProperties(IEnumerable properties) { - return properties.Where(p => PropertyUtility.GetAttribute(p) == null); + return properties.Where(p => PropertyUtility.GetAttribute(p.serializedProperty) == null && !p.serializedProperty.name.Equals("m_Script")); } - private static IEnumerable> GetGroupedProperties(IEnumerable properties) + private static IEnumerable> GetGroupedProperties(IEnumerable properties) { return properties - .Where(p => PropertyUtility.GetAttribute(p) != null) - .GroupBy(p => PropertyUtility.GetAttribute(p).Name); + .Where(p => PropertyUtility.GetAttribute(p.serializedProperty) != null) + .GroupBy(p => PropertyUtility.GetAttribute(p.serializedProperty).Name); } - private static IEnumerable> GetFoldoutProperties(IEnumerable properties) + private static IEnumerable> GetFoldoutProperties(IEnumerable properties) { return properties - .Where(p => PropertyUtility.GetAttribute(p) != null) - .GroupBy(p => PropertyUtility.GetAttribute(p).Name); + .Where(p => PropertyUtility.GetAttribute(p.serializedProperty) != null) + .GroupBy(p => PropertyUtility.GetAttribute(p.serializedProperty).Name); } private static GUIStyle GetHeaderGUIStyle() diff --git a/Assets/NaughtyAttributes/Scripts/Editor/NaughtyProperty.cs b/Assets/NaughtyAttributes/Scripts/Editor/NaughtyProperty.cs new file mode 100644 index 00000000..2a68e6b3 --- /dev/null +++ b/Assets/NaughtyAttributes/Scripts/Editor/NaughtyProperty.cs @@ -0,0 +1,21 @@ +using UnityEditor; + +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; + + public bool cachedIsVisible = true; + public bool cachedIsEnabled = true; + } +} diff --git a/Assets/NaughtyAttributes/Scripts/Editor/NaughtyProperty.cs.meta b/Assets/NaughtyAttributes/Scripts/Editor/NaughtyProperty.cs.meta new file mode 100644 index 00000000..cbb03379 --- /dev/null +++ b/Assets/NaughtyAttributes/Scripts/Editor/NaughtyProperty.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 12288d0262da08245af3b1fef6421c75 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/AnimatorParamPropertyDrawer.cs b/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/AnimatorParamPropertyDrawer.cs index 451686b1..078f6086 100644 --- a/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/AnimatorParamPropertyDrawer.cs +++ b/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/AnimatorParamPropertyDrawer.cs @@ -9,13 +9,25 @@ 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"; + private AnimatorController _cachedAnimatorController; + protected override float GetPropertyHeight_Internal(SerializedProperty property, GUIContent label) { - AnimatorParamAttribute animatorParamAttribute = PropertyUtility.GetAttribute(property); - bool validAnimatorController = GetAnimatorController(property, animatorParamAttribute.AnimatorName) != null; + if (_cachedAnimatorParamAttribute == null) + _cachedAnimatorParamAttribute = PropertyUtility.GetAttribute(property); + + AnimatorParamAttribute animatorParamAttribute = _cachedAnimatorParamAttribute; + + if (_cachedAnimatorController == null) + _cachedAnimatorController = GetAnimatorController(property, animatorParamAttribute.AnimatorName); + + bool validAnimatorController = _cachedAnimatorController != null; + bool validPropertyType = property.propertyType == SerializedPropertyType.Integer || property.propertyType == SerializedPropertyType.String; return (validAnimatorController && validPropertyType) @@ -27,9 +39,12 @@ 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); + AnimatorController animatorController = _cachedAnimatorController; if (animatorController == null) { DrawDefaultPropertyAndHelpBox(rect, property, InvalidAnimatorControllerWarningMessage, MessageType.Warning); @@ -131,39 +146,60 @@ private static AnimatorController GetAnimatorController(SerializedProperty prope object target = PropertyUtility.GetTargetObjectWithProperty(property); FieldInfo animatorFieldInfo = ReflectionUtility.GetField(target, animatorName); - if (animatorFieldInfo != null && - animatorFieldInfo.FieldType == typeof(Animator)) + if (animatorFieldInfo != null) { - Animator animator = animatorFieldInfo.GetValue(target) as Animator; - if (animator != null) + if (animatorFieldInfo.FieldType == typeof(Animator)) { - AnimatorController animatorController = animator.runtimeAnimatorController as AnimatorController; - return animatorController; + Animator animator = animatorFieldInfo.GetValue(target) as Animator; + if (animator != null) + { + AnimatorController animatorController = + animator.runtimeAnimatorController as AnimatorController; + return animatorController; + } + } + else if (animatorFieldInfo.FieldType == typeof(AnimatorController)) + { + return animatorFieldInfo.GetValue(target) as AnimatorController; } } PropertyInfo animatorPropertyInfo = ReflectionUtility.GetProperty(target, animatorName); - if (animatorPropertyInfo != null && - animatorPropertyInfo.PropertyType == typeof(Animator)) + if (animatorPropertyInfo != null) { - Animator animator = animatorPropertyInfo.GetValue(target) as Animator; - if (animator != null) + if (animatorPropertyInfo.PropertyType == typeof(Animator)) + { + Animator animator = animatorPropertyInfo.GetValue(target) as Animator; + if (animator != null) + { + AnimatorController animatorController = + animator.runtimeAnimatorController as AnimatorController; + return animatorController; + } + } + else if (animatorPropertyInfo.PropertyType == typeof(AnimatorController)) { - AnimatorController animatorController = animator.runtimeAnimatorController as AnimatorController; - return animatorController; + return animatorPropertyInfo.GetValue(target) as AnimatorController; } } MethodInfo animatorGetterMethodInfo = ReflectionUtility.GetMethod(target, animatorName); if (animatorGetterMethodInfo != null && - animatorGetterMethodInfo.ReturnType == typeof(Animator) && - animatorGetterMethodInfo.GetParameters().Length == 0) + animatorGetterMethodInfo.GetParameters().Length == 0) { - Animator animator = animatorGetterMethodInfo.Invoke(target, null) as Animator; - if (animator != null) + if (animatorGetterMethodInfo.ReturnType == typeof(Animator)) + { + Animator animator = animatorGetterMethodInfo.Invoke(target, null) as Animator; + if (animator != null) + { + AnimatorController animatorController = + animator.runtimeAnimatorController as AnimatorController; + return animatorController; + } + } + else if (animatorGetterMethodInfo.ReturnType == typeof(AnimatorController)) { - AnimatorController animatorController = animator.runtimeAnimatorController as AnimatorController; - return animatorController; + return animatorGetterMethodInfo.Invoke(target, null) as AnimatorController; } } 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/ExpandablePropertyDrawer.cs b/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/ExpandablePropertyDrawer.cs index 2c485b7f..d2b13cd5 100644 --- a/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/ExpandablePropertyDrawer.cs +++ b/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers/ExpandablePropertyDrawer.cs @@ -128,7 +128,7 @@ protected override void OnGUI_Internal(Rect rect, SerializedProperty property, G EditorGUI.EndProperty(); } - + private void DrawChildProperties(Rect rect, SerializedProperty property) { ScriptableObject scriptableObject = property.objectReferenceValue as ScriptableObject; @@ -180,7 +180,9 @@ private void DrawChildProperties(Rect rect, SerializedProperty property) height = childHeight }; - NaughtyEditorGUI.PropertyField(childRect, childProperty, true); + //TODO since the depth can go deeper we cant just use one field. - need better caching and mapping here! + //_naughtyProperty ??= PropertyUtility.CreateNaughtyProperty(childProperty); + NaughtyEditorGUI.PropertyField(childRect, PropertyUtility.CreateNaughtyProperty(childProperty), true); yOffset += childHeight; } 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/PropertyDrawers_SpecialCase/SpecialCasePropertyDrawerBase.cs b/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers_SpecialCase/SpecialCasePropertyDrawerBase.cs index 8f283d0b..6f82f901 100644 --- a/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers_SpecialCase/SpecialCasePropertyDrawerBase.cs +++ b/Assets/NaughtyAttributes/Scripts/Editor/PropertyDrawers_SpecialCase/SpecialCasePropertyDrawerBase.cs @@ -7,36 +7,41 @@ namespace NaughtyAttributes.Editor { public abstract class SpecialCasePropertyDrawerBase { - public void OnGUI(Rect rect, SerializedProperty property) + public bool OnGUI(Rect rect, NaughtyProperty naughtyProperty) { + bool changeDetected = false; + // Check if visible - bool visible = PropertyUtility.IsVisible(property); + bool visible = PropertyUtility.IsVisible(naughtyProperty.showIfAttribute, naughtyProperty.serializedProperty); if (!visible) { - return; + return false; } // Validate - ValidatorAttribute[] validatorAttributes = PropertyUtility.GetAttributes(property); + ValidatorAttribute[] validatorAttributes = naughtyProperty.validatorAttributes; foreach (var validatorAttribute in validatorAttributes) { - validatorAttribute.GetValidator().ValidateProperty(property); + validatorAttribute.GetValidator().ValidateProperty(naughtyProperty.serializedProperty); } // Check if enabled and draw EditorGUI.BeginChangeCheck(); - bool enabled = PropertyUtility.IsEnabled(property); + bool enabled = PropertyUtility.IsEnabled(naughtyProperty.readOnlyAttribute, naughtyProperty.enableIfAttribute, naughtyProperty.serializedProperty); using (new EditorGUI.DisabledScope(disabled: !enabled)) { - OnGUI_Internal(rect, property, PropertyUtility.GetLabel(property)); + OnGUI_Internal(rect, naughtyProperty.serializedProperty, PropertyUtility.GetLabel(naughtyProperty.labelAttribute, naughtyProperty.serializedProperty)); } // Call OnValueChanged callbacks if (EditorGUI.EndChangeCheck()) { - PropertyUtility.CallOnValueChangedCallbacks(property); + changeDetected = true; + PropertyUtility.CallOnValueChangedCallbacks(naughtyProperty.serializedProperty); } + + return changeDetected; } public float GetPropertyHeight(SerializedProperty property) 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/NaughtyEditorGUI.cs b/Assets/NaughtyAttributes/Scripts/Editor/Utility/NaughtyEditorGUI.cs index 08d77860..51a1d9f3 100644 --- a/Assets/NaughtyAttributes/Scripts/Editor/Utility/NaughtyEditorGUI.cs +++ b/Assets/NaughtyAttributes/Scripts/Editor/Utility/NaughtyEditorGUI.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Linq; using System.Reflection; + using UnityEditor; using UnityEditor.Experimental.SceneManagement; using UnityEditor.SceneManagement; @@ -16,67 +17,69 @@ public static class NaughtyEditorGUI private static GUIStyle _buttonStyle = new GUIStyle(GUI.skin.button) { richText = true }; - private delegate void PropertyFieldFunction(Rect rect, SerializedProperty property, GUIContent label, bool includeChildren); + private delegate void PropertyFieldFunction(Rect rect, NaughtyProperty naughtyProperty, GUIContent label, bool includeChildren); - public static void PropertyField(Rect rect, SerializedProperty property, bool includeChildren) + public static bool PropertyField(Rect rect, NaughtyProperty naughtyProperty, bool includeChildren) { - PropertyField_Implementation(rect, property, includeChildren, DrawPropertyField); + return PropertyField_Implementation(rect, naughtyProperty, includeChildren, DrawPropertyField); } - public static void PropertyField_Layout(SerializedProperty property, bool includeChildren) + public static bool PropertyField_Layout(NaughtyProperty naughtyProperty, bool includeChildren) { Rect dummyRect = new Rect(); - PropertyField_Implementation(dummyRect, property, includeChildren, DrawPropertyField_Layout); + return PropertyField_Implementation(dummyRect, naughtyProperty, includeChildren, DrawPropertyField_Layout); } - private static void DrawPropertyField(Rect rect, SerializedProperty property, GUIContent label, bool includeChildren) + private static void DrawPropertyField(Rect rect, NaughtyProperty naughtyProperty, GUIContent label, bool includeChildren) { - EditorGUI.PropertyField(rect, property, label, includeChildren); + EditorGUI.PropertyField(rect, naughtyProperty.serializedProperty, label, includeChildren); } - private static void DrawPropertyField_Layout(Rect rect, SerializedProperty property, GUIContent label, bool includeChildren) + private static void DrawPropertyField_Layout(Rect rect, NaughtyProperty naughtyProperty, GUIContent label, bool includeChildren) { - EditorGUILayout.PropertyField(property, label, includeChildren); + EditorGUILayout.PropertyField(naughtyProperty.serializedProperty, label, includeChildren); } - private static void PropertyField_Implementation(Rect rect, SerializedProperty property, bool includeChildren, PropertyFieldFunction propertyFieldFunction) + private static bool PropertyField_Implementation(Rect rect, NaughtyProperty naughtyProperty, bool includeChildren, PropertyFieldFunction propertyFieldFunction) { - SpecialCaseDrawerAttribute specialCaseAttribute = PropertyUtility.GetAttribute(property); - if (specialCaseAttribute != null) + bool changeDetected = false; + + if (naughtyProperty.specialCaseDrawerAttribute != null) { - specialCaseAttribute.GetDrawer().OnGUI(rect, property); + return naughtyProperty.specialCaseDrawerAttribute.GetDrawer().OnGUI(rect, naughtyProperty); } else { // Check if visible - bool visible = PropertyUtility.IsVisible(property); - if (!visible) + if (!naughtyProperty.cachedIsVisible) { - return; + return false; } - + // Validate - ValidatorAttribute[] validatorAttributes = PropertyUtility.GetAttributes(property); - foreach (var validatorAttribute in validatorAttributes) + foreach (var validatorAttribute in naughtyProperty.validatorAttributes) { - validatorAttribute.GetValidator().ValidateProperty(property); + validatorAttribute.GetValidator().ValidateProperty(naughtyProperty.serializedProperty); } - + // Check if enabled and draw EditorGUI.BeginChangeCheck(); - bool enabled = PropertyUtility.IsEnabled(property); - + bool enabled = naughtyProperty.cachedIsEnabled; + using (new EditorGUI.DisabledScope(disabled: !enabled)) { - propertyFieldFunction.Invoke(rect, property, PropertyUtility.GetLabel(property), includeChildren); + propertyFieldFunction.Invoke(rect, naughtyProperty, PropertyUtility.GetLabel(naughtyProperty.labelAttribute, naughtyProperty.serializedProperty), includeChildren); } - + // Call OnValueChanged callbacks if (EditorGUI.EndChangeCheck()) { - PropertyUtility.CallOnValueChangedCallbacks(property); + changeDetected = true; + PropertyUtility.CallOnValueChangedCallbacks(naughtyProperty.serializedProperty); } } + + return changeDetected; } public static float GetIndentLength(Rect sourceRect) diff --git a/Assets/NaughtyAttributes/Scripts/Editor/Utility/PropertyUtility.cs b/Assets/NaughtyAttributes/Scripts/Editor/Utility/PropertyUtility.cs index 8a9b2c59..4f7dc6f1 100644 --- a/Assets/NaughtyAttributes/Scripts/Editor/Utility/PropertyUtility.cs +++ b/Assets/NaughtyAttributes/Scripts/Editor/Utility/PropertyUtility.cs @@ -26,9 +26,33 @@ public static T[] GetAttributes(SerializedProperty property) where T : class return (T[])fieldInfo.GetCustomAttributes(typeof(T), true); } + public static NaughtyProperty CreateNaughtyProperty(SerializedProperty serializedProperty) + { + NaughtyProperty naughtyProperty = new NaughtyProperty(); + naughtyProperty.serializedProperty = serializedProperty; + + naughtyProperty.readOnlyAttribute = PropertyUtility.GetAttribute(serializedProperty); + naughtyProperty.enableIfAttribute = PropertyUtility.GetAttribute(serializedProperty); + + naughtyProperty.showIfAttribute = PropertyUtility.GetAttribute(serializedProperty); + naughtyProperty.validatorAttributes = PropertyUtility.GetAttributes(serializedProperty); + + naughtyProperty.labelAttribute = PropertyUtility.GetAttribute(serializedProperty); + + naughtyProperty.specialCaseDrawerAttribute = + PropertyUtility.GetAttribute(serializedProperty); + + return naughtyProperty; + } + public static GUIContent GetLabel(SerializedProperty property) { LabelAttribute labelAttribute = GetAttribute(property); + return GetLabel(labelAttribute, property); + } + + public static GUIContent GetLabel(LabelAttribute labelAttribute, SerializedProperty property) + { string labelText = (labelAttribute == null) ? property.displayName : labelAttribute.Label; @@ -71,17 +95,23 @@ public static void CallOnValueChangedCallbacks(SerializedProperty property) public static bool IsEnabled(SerializedProperty property) { ReadOnlyAttribute readOnlyAttribute = GetAttribute(property); + EnableIfAttributeBase enableIfAttribute = GetAttribute(property); + + return IsEnabled(readOnlyAttribute, enableIfAttribute, property); + } + + public static bool IsEnabled(ReadOnlyAttribute readOnlyAttribute, EnableIfAttributeBase enableIfAttribute, SerializedProperty property) + { if (readOnlyAttribute != null) { return false; } - - EnableIfAttributeBase enableIfAttribute = GetAttribute(property); + if (enableIfAttribute == null) { return true; } - + object target = GetTargetObjectWithProperty(property); // deal with enum conditions @@ -118,15 +148,21 @@ public static bool IsEnabled(SerializedProperty property) return false; } } - + public static bool IsVisible(SerializedProperty property) { ShowIfAttributeBase showIfAttribute = GetAttribute(property); + + return IsVisible(showIfAttribute, property); + } + + public static bool IsVisible(ShowIfAttributeBase showIfAttribute, SerializedProperty property) + { if (showIfAttribute == null) { return true; } - + object target = GetTargetObjectWithProperty(property); // deal with enum conditions @@ -142,7 +178,8 @@ public static bool IsVisible(SerializedProperty property) return matched != showIfAttribute.Inverted; } - string message = showIfAttribute.GetType().Name + " needs a valid enum field, property or method name to work"; + string message = showIfAttribute.GetType().Name + + " needs a valid enum field, property or method name to work"; Debug.LogWarning(message, property.serializedObject.targetObject); return false; @@ -152,12 +189,14 @@ public static bool IsVisible(SerializedProperty property) List conditionValues = GetConditionValues(target, showIfAttribute.Conditions); if (conditionValues.Count > 0) { - bool enabled = GetConditionsFlag(conditionValues, showIfAttribute.ConditionOperator, showIfAttribute.Inverted); + bool enabled = GetConditionsFlag(conditionValues, showIfAttribute.ConditionOperator, + showIfAttribute.Inverted); return enabled; } else { - string message = showIfAttribute.GetType().Name + " needs a valid boolean condition field, property or method name to work"; + string message = showIfAttribute.GetType().Name + + " needs a valid boolean condition field, property or method name to work"; Debug.LogWarning(message, property.serializedObject.targetObject); return false; diff --git a/Assets/NaughtyAttributes/Scripts/Test/AnimatorParamTest.cs b/Assets/NaughtyAttributes/Scripts/Test/AnimatorParamTest.cs index 0bbc476c..775e9206 100644 --- a/Assets/NaughtyAttributes/Scripts/Test/AnimatorParamTest.cs +++ b/Assets/NaughtyAttributes/Scripts/Test/AnimatorParamTest.cs @@ -6,20 +6,33 @@ public class AnimatorParamTest : MonoBehaviour { public Animator animator0; +#if UNITY_EDITOR + public UnityEditor.Animations.AnimatorController animatorController0; +#endif + [AnimatorParam("animator0")] public int hash0; - [AnimatorParam("animator0")] public string name0; + + [AnimatorParam("animatorController0")] + public int hashController0; + + [AnimatorParam("animatorController0")] + public string nameController0; public AnimatorParamNest1 nest1; - [Button("Log 'hash0' and 'name0'")] + [Button("Log 'hash0', 'hashController0' and 'name0', 'nameController0'")] private void TestLog() { Debug.Log($"hash0 = {hash0}"); Debug.Log($"name0 = {name0}"); Debug.Log($"Animator.StringToHash(name0) = {Animator.StringToHash(name0)}"); + + Debug.Log($"hashController0 = {hashController0}"); + Debug.Log($"nameController0 = {nameController0}"); + Debug.Log($"Animator.StringToHash(nameController0) = {Animator.StringToHash(nameController0)}"); } } @@ -27,14 +40,29 @@ private void TestLog() public class AnimatorParamNest1 { public Animator animator1; + +#if UNITY_EDITOR + public UnityEditor.Animations.AnimatorController animatorController1; +#endif + private Animator Animator1 => animator1; - + +#if UNITY_EDITOR + private UnityEditor.Animations.AnimatorController AnimatorController1 => animatorController1; +#endif + [AnimatorParam("Animator1", AnimatorControllerParameterType.Bool)] public int hash1; [AnimatorParam("Animator1", AnimatorControllerParameterType.Float)] public string name1; + + [AnimatorParam("AnimatorController1", AnimatorControllerParameterType.Bool)] + public int hashController1; + [AnimatorParam("AnimatorController1", AnimatorControllerParameterType.Float)] + public string nameController1; + public AnimatorParamNest2 nest2; } @@ -42,12 +70,27 @@ public class AnimatorParamNest1 public class AnimatorParamNest2 { public Animator animator2; + +#if UNITY_EDITOR + public UnityEditor.Animations.AnimatorController animatorController2; +#endif + private Animator GetAnimator2() => animator2; - + +#if UNITY_EDITOR + private UnityEditor.Animations.AnimatorController GetAnimatorController2() => animatorController2; +#endif + [AnimatorParam("GetAnimator2", AnimatorControllerParameterType.Int)] public int hash1; [AnimatorParam("GetAnimator2", AnimatorControllerParameterType.Trigger)] public string name1; + + [AnimatorParam("GetAnimatorController2", AnimatorControllerParameterType.Int)] + public int hashController2; + + [AnimatorParam("GetAnimatorController2", AnimatorControllerParameterType.Trigger)] + public string nameController2; } } diff --git a/Assets/NaughtyAttributes/Scripts/Test/CurveRangeTest.cs b/Assets/NaughtyAttributes/Scripts/Test/CurveRangeTest.cs index 697aaaa8..134abe6c 100644 --- a/Assets/NaughtyAttributes/Scripts/Test/CurveRangeTest.cs +++ b/Assets/NaughtyAttributes/Scripts/Test/CurveRangeTest.cs @@ -1,32 +1,30 @@ using UnityEngine; using NaughtyAttributes; -public class CurveRangeTest : MonoBehaviour +namespace NaughtyAttributes.Test { - [CurveRange(-1, -1, 1, 1, EColor.Red)] - public AnimationCurve curve; + public class CurveRangeTest : MonoBehaviour + { + [CurveRange(-1, -1, 1, 1, EColor.Red)] public AnimationCurve curve; - [CurveRange(EColor.Orange)] - public AnimationCurve curve1; + [CurveRange(EColor.Orange)] public AnimationCurve curve1; - [CurveRange(0, 0, 10, 10)] - public AnimationCurve curve2; + [CurveRange(0, 0, 10, 10)] public AnimationCurve curve2; - public CurveRangeNest1 nest1; + public CurveRangeNest1 nest1; - [System.Serializable] - public class CurveRangeNest1 - { - [CurveRange(0, 0, 1, 1, EColor.Green)] - public AnimationCurve curve; + [System.Serializable] + public class CurveRangeNest1 + { + [CurveRange(0, 0, 1, 1, EColor.Green)] public AnimationCurve curve; - public CurveRangeNest2 nest2; - } + public CurveRangeNest2 nest2; + } - [System.Serializable] - public class CurveRangeNest2 - { - [CurveRange(0, 0, 5, 5, EColor.Blue)] - public AnimationCurve curve; + [System.Serializable] + public class CurveRangeNest2 + { + [CurveRange(0, 0, 5, 5, EColor.Blue)] public AnimationCurve curve; + } } } diff --git a/Assets/NaughtyAttributes/Scripts/Test/HugeMixPerformanceTest.cs b/Assets/NaughtyAttributes/Scripts/Test/HugeMixPerformanceTest.cs new file mode 100644 index 00000000..9291271d --- /dev/null +++ b/Assets/NaughtyAttributes/Scripts/Test/HugeMixPerformanceTest.cs @@ -0,0 +1,304 @@ +using System.Collections; +using UnityEngine; + +namespace NaughtyAttributes.Test +{ + public class HugeMixPerformanceTest : MonoBehaviour + { + #region AnimatorParamTest + + public Animator animator0; + + [AnimatorParam("animator0")] + public int hash0; + + [AnimatorParam("animator0")] + public string name0; + + public AnimatorParamNest1 animatorParamNest1; + + [Button("Log 'hash0' and 'name0'")] + private void TestLog() + { + Debug.Log($"hash0 = {hash0}"); + Debug.Log($"name0 = {name0}"); + Debug.Log($"Animator.StringToHash(name0) = {Animator.StringToHash(name0)}"); + } + + #endregion + + #region BoxGroupTest + + [BoxGroup("Integers")] + public int int0; + [BoxGroup("Integers")] + public int int1; + + [BoxGroup("Floats")] + public float float0; + [BoxGroup("Floats")] + public float float1; + + [BoxGroup("Sliders")] + [MinMaxSlider(0, 1)] + public Vector2 slider0; + [BoxGroup("Sliders")] + [MinMaxSlider(0, 1)] + public Vector2 slider1; + + public string str0; + public string str1; + + [BoxGroup] + public Transform trans0; + [BoxGroup] + public Transform trans1; + + #endregion + + #region ButtonTest + + public int myInt; + + [Button(enabledMode: EButtonEnableMode.Always)] + private void IncrementMyInt() + { + myInt++; + } + + [Button("Decrement My Int", EButtonEnableMode.Editor)] + private void DecrementMyInt() + { + myInt--; + } + + [Button(enabledMode: EButtonEnableMode.Playmode)] + private void LogMyInt(string prefix = "MyInt = ") + { + Debug.Log(prefix + myInt); + } + + [Button("StartCoroutine")] + private IEnumerator IncrementMyIntCoroutine() + { + int seconds = 5; + for (int i = 0; i < seconds; i++) + { + myInt++; + yield return new WaitForSeconds(1.0f); + } + } + + #endregion + + #region CurveRangeTest + + [CurveRange(-1, -1, 1, 1, EColor.Red)] public AnimationCurve curve; + + [CurveRange(EColor.Orange)] public AnimationCurve curve1; + + [CurveRange(0, 0, 10, 10)] public AnimationCurve curve2; + + public CurveRangeNest1 curveRangeNest1; + + [System.Serializable] + public class CurveRangeNest1 + { + [CurveRange(0, 0, 1, 1, EColor.Green)] public AnimationCurve curve; + + public CurveRangeNest2 curveRangeNest2; + } + + [System.Serializable] + public class CurveRangeNest2 + { + [CurveRange(0, 0, 5, 5, EColor.Blue)] public AnimationCurve curve; + } + + #endregion + + #region DisableIfTest + + public bool disableIf1; + public bool disableIf2; + public DisableIfEnum disableIfEnum1; + [EnumFlags] public DisableIfEnumFlag disableIfEnum2; + + [DisableIf(EConditionOperator.And, "disableIf1", "disableIf2")] + [ReorderableList] + public int[] disableIfAll; + + [DisableIf(EConditionOperator.Or, "disableIf1", "disableIf2")] + [ReorderableList] + public int[] disableIfAny; + + [DisableIf("disableIfEnum1", DisableIfEnum.Case0)] + [ReorderableList] + public int[] disableIfEnum; + + [DisableIf("disableIfEnum2", DisableIfEnumFlag.Flag0)] + [ReorderableList] + public int[] disableIfEnumFlag; + + [DisableIf("disableIfEnum2", DisableIfEnumFlag.Flag0 | DisableIfEnumFlag.Flag1)] + [ReorderableList] + public int[] disableIfEnumFlagMulti; + + public DisableIfNest1 disableIfNest1; + + #endregion + + #region DropDownTest + + [Dropdown("dropDownIntValues")] + public int dropDownIntValue; + +#pragma warning disable 414 + private int[] dropDownIntValues = new int[] { 1, 2, 3 }; +#pragma warning restore 414 + + public DropdownNest1 dropdownNest1; + + #endregion + + #region EnableIfTest + + public bool enable1; + public bool enable2; + public EnableIfEnum enableIfEnum1; + [EnumFlags] public EnableIfEnumFlag enableIfEnum2; + + [EnableIf(EConditionOperator.And, "enable1", "enable2")] + [ReorderableList] + public int[] enableIfAll; + + [EnableIf(EConditionOperator.Or, "enable1", "enable2")] + [ReorderableList] + public int[] enableIfAny; + + [EnableIf("enableIfEnum1", EnableIfEnum.Case0)] + [ReorderableList] + public int[] enableIfEnum; + + [EnableIf("enableIfEnum2", EnableIfEnumFlag.Flag0)] + [ReorderableList] + public int[] enableIfEnumFlag; + + [EnableIf("enableIfEnum2", EnableIfEnumFlag.Flag0 | EnableIfEnumFlag.Flag1)] + [ReorderableList] + public int[] enableIfEnumFlagMulti; + + public EnableIfNest1 enableIfNest1; + + #endregion + + #region EnumFlagsTest + + [EnumFlags] + public TestEnum enumFlagsTest0; + + public EnumFlagsNest1 enumFlagsNest1; + + #endregion + + #region ExpandableTest + + [Expandable] + public ScriptableObject obj0; + + public ExpandableScriptableObjectNest1 expandableScriptableObjectNest1; + + #endregion + + #region FoldoutTest + + [Foldout("Integers")] + public int foldoutTestInt0; + [Foldout("Integers")] + public int foldoutTestInt1; + + [Foldout("Floats")] + public float foldoutTestFloat0; + [Foldout("Floats")] + public float foldoutTestFloat1; + + [Foldout("Sliders")] + [MinMaxSlider(0, 1)] + public Vector2 foldoutTestSlider0; + [Foldout("Sliders")] + [MinMaxSlider(0, 1)] + public Vector2 foldoutTestSlider1; + + public string foldoutTestStr0; + public string foldoutTestStr1; + + [Foldout("Transforms")] + public Transform foldoutTestTrans0; + [Foldout("Transforms")] + public Transform foldoutTestTrans1; + + #endregion + + #region HideIfTest + + public bool hide1; + public bool hide2; + public HideIfEnum hideIfEnum1; + [EnumFlags] public HideIfEnumFlag hideIfEnum2; + + [HideIf(EConditionOperator.And, "hide1", "hide2")] + [ReorderableList] + public int[] hideIfAll; + + [HideIf(EConditionOperator.Or, "hide1", "hide2")] + [ReorderableList] + public int[] hideIfAny; + + [HideIf("hideIfEnum1", HideIfEnum.Case0)] + [ReorderableList] + public int[] hideIfEnum; + + [HideIf("hideIfEnum2", HideIfEnumFlag.Flag0)] + [ReorderableList] + public int[] hideIfEnumFlag; + + [HideIf("hideIfEnum2", HideIfEnumFlag.Flag0 | HideIfEnumFlag.Flag1)] + [ReorderableList] + public int[] hideIfEnumFlagMulti; + + public HideIfNest1 hideIfNest1; + + #endregion + + #region ShowIfTest + + public bool showIf1; + public bool showIf2; + public ShowIfEnum showIfEnum1; + [EnumFlags] public ShowIfEnumFlag showIfEnum2; + + [ShowIf(EConditionOperator.And, "showIf1", "showIf2")] + [ReorderableList] + public int[] showIfAll; + + [ShowIf(EConditionOperator.Or, "showIf1", "showIf2")] + [ReorderableList] + public int[] showIfAny; + + [ShowIf("showIfEnum1", ShowIfEnum.Case0)] + [ReorderableList] + public int[] showIfEnum; + + [ShowIf("showIfEnum2", ShowIfEnumFlag.Flag0)] + [ReorderableList] + public int[] showIfEnumFlag; + + [ShowIf("showIfEnum2", ShowIfEnumFlag.Flag0 | ShowIfEnumFlag.Flag1)] + [ReorderableList] + public int[] showIfEnumFlagMulti; + + public ShowIfNest1 showIfNest1; + + #endregion + } +} diff --git a/Assets/NaughtyAttributes/Scripts/Test/HugeMixPerformanceTest.cs.meta b/Assets/NaughtyAttributes/Scripts/Test/HugeMixPerformanceTest.cs.meta new file mode 100644 index 00000000..8222c32a --- /dev/null +++ b/Assets/NaughtyAttributes/Scripts/Test/HugeMixPerformanceTest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9d0844cc6e62fe54393612902562c4e2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/NaughtyAttributes/Scripts/Test/_NaughtyScriptableObject.cs b/Assets/NaughtyAttributes/Scripts/Test/_NaughtyScriptableObject.cs index f2cb1b68..41609c8d 100644 --- a/Assets/NaughtyAttributes/Scripts/Test/_NaughtyScriptableObject.cs +++ b/Assets/NaughtyAttributes/Scripts/Test/_NaughtyScriptableObject.cs @@ -8,5 +8,24 @@ public class _NaughtyScriptableObject : ScriptableObject { [Expandable] public List<_TestScriptableObject> list; + +#if UNITY_EDITOR + public UnityEditor.Animations.AnimatorController animatorController0; +#endif + + [AnimatorParam("animatorController0")] + public int hashController0; + + [AnimatorParam("animatorController0")] + public string nameController0; + + + [Button("Log 'hashController0' and 'nameController0'")] + private void TestLog() + { + Debug.Log($"hashController0 = {hashController0}"); + Debug.Log($"nameController0 = {nameController0}"); + Debug.Log($"Animator.StringToHash(nameController0) = {Animator.StringToHash(nameController0)}"); + } } }