From c575a704f0e0b630a24a67ce5f643bac2568e70e Mon Sep 17 00:00:00 2001 From: uurha Date: Sun, 21 Apr 2024 08:41:35 +0200 Subject: [PATCH] Fix minor display bugs --- .../Drawers/Misc/Wrappers/HideLabelWrapper.cs | 42 ++++++---- .../Drawers/Preview/PreviewDrawer.cs | 7 +- .../Drawers/Select/SelectDrawer.cs | 2 +- .../Drawers/Select/SelectDrawerBase.cs | 18 ++++- .../SetupStrategies/DropdownStrategy.cs | 5 ++ .../SetupStrategies/SelectEnumStrategy.cs | 5 ++ .../SelectImplementationStrategy.cs | 24 +++++- ...egy.cs => SelectSerializedTypeStrategy.cs} | 11 ++- ...a => SelectSerializedTypeStrategy.cs.meta} | 0 .../Select/SetupStrategies/SetupStrategy.cs | 1 + .../Select/Wrappers/BaseSelectWrapper.cs | 56 +++++++++++--- .../Select/Wrappers/DropdownWrapper.cs | 13 +--- .../Select/Wrappers/SelectEnumWrapper.cs | 21 +++-- .../Wrappers/SelectSerializedTypeWrapper.cs | 11 --- .../Select/Wrappers/SelectTypeWrapper.cs | 28 ------- .../Drawers/Utility/SelectUtility.cs | 2 +- .../Attributes/Misc/CustomTooltipAttribute.cs | 1 + .../Samples~/TestSamples/Scripts/Test.cs | 76 +++++++++---------- Assets/BetterAttributes/package.json | 2 +- Packages/manifest.json | 2 +- Packages/packages-lock.json | 2 +- 21 files changed, 186 insertions(+), 143 deletions(-) rename Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/{SelectTypeStrategy.cs => SelectSerializedTypeStrategy.cs} (92%) rename Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/{SelectTypeStrategy.cs.meta => SelectSerializedTypeStrategy.cs.meta} (100%) diff --git a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Misc/Wrappers/HideLabelWrapper.cs b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Misc/Wrappers/HideLabelWrapper.cs index 8e27ceb..0dda682 100644 --- a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Misc/Wrappers/HideLabelWrapper.cs +++ b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Misc/Wrappers/HideLabelWrapper.cs @@ -1,3 +1,4 @@ +using System; using Better.Commons.EditorAddons.Drawers.Caching; using Better.Commons.EditorAddons.Utility; using UnityEditor; @@ -26,17 +27,23 @@ public override void DrawField(Rect rect, GUIContent label) return; } - var enumerator = _property.GetEnumerator(); - var copy = new Rect(rect); - while (enumerator.MoveNext()) + var serializedProperty = _property.Copy(); + var enumerator = serializedProperty.GetEnumerator(); + using (var disposable = enumerator as IDisposable) { - if (!(enumerator.Current is SerializedProperty prop)) continue; + var copy = new Rect(rect); + while (enumerator.MoveNext()) + { + if (!(enumerator.Current is SerializedProperty prop)) continue; - var propertyHeight = EditorGUI.GetPropertyHeight(prop, true); - copy.height = propertyHeight; + var propertyHeight = EditorGUI.GetPropertyHeight(prop, true); + copy.height = propertyHeight; - PropertyFieldUtility.PropertyFieldSafe(copy, prop, item); - copy.y += propertyHeight + EditorGUIUtility.standardVerticalSpacing; + PropertyFieldUtility.PropertyFieldSafe(copy, prop, item); + copy.y += propertyHeight + EditorGUIUtility.standardVerticalSpacing; + } + + serializedProperty.Dispose(); } } @@ -49,15 +56,20 @@ public override HeightCacheValue GetHeight(GUIContent label) return HeightCacheValue.GetFull(height); } - var enumerator = _property.GetEnumerator(); - while (enumerator.MoveNext()) + var serializedProperty = _property.Copy(); + var enumerator = serializedProperty.GetEnumerator(); + using (var disposable = enumerator as IDisposable) { - var prop = enumerator.Current as SerializedProperty; - if (prop == null) continue; - height += EditorGUI.GetPropertyHeight(prop, true) + EditorGUIUtility.standardVerticalSpacing; - } + while (enumerator.MoveNext()) + { + var prop = enumerator.Current as SerializedProperty; + if (prop == null) continue; + height += EditorGUI.GetPropertyHeight(prop, true) + EditorGUIUtility.standardVerticalSpacing; + } - return HeightCacheValue.GetFull(height); + serializedProperty.Dispose(); + return HeightCacheValue.GetFull(height); + } } } } \ No newline at end of file diff --git a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Preview/PreviewDrawer.cs b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Preview/PreviewDrawer.cs index 4579f5c..3df4905 100644 --- a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Preview/PreviewDrawer.cs +++ b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Preview/PreviewDrawer.cs @@ -47,14 +47,14 @@ protected override bool PreDraw(ref Rect position, SerializedProperty property, _previewSize = ((PreviewAttribute)_attribute).PreviewSize; if (!Collection.ValidateObject(property)) { - ExtendedGUIUtility.HelpBoxFromRect(position, property, label, Message, IconType.WarningMessage); + var offset = EditorGUI.GetPropertyHeight(property, label, true) + ExtendedGUIUtility.SpaceHeight; + ExtendedGUIUtility.HelpBoxFromRect(position, property, label, Message, IconType.WarningMessage, offset); return true; } label.image = IconType.View.GetIcon(); var copy = ExtendedGUIUtility.GetClickRect(position, label); copy.height = EditorGUIUtility.singleLineHeight; - Collection.PreDraw(copy, property, _previewSize, _objectChanged); return true; @@ -65,7 +65,8 @@ protected override HeightCacheValue GetPropertyHeight(SerializedProperty propert if (!Collection.ValidateObject(property)) { var additive = ExtendedGUIUtility.GetHelpBoxHeight(EditorGUIUtility.currentViewWidth, Message, IconType.WarningMessage); - return HeightCacheValue.GetAdditive(additive + ExtendedGUIUtility.SpaceHeight * 2); + var height = HeightCacheValue.GetAdditive(additive + ExtendedGUIUtility.SpaceHeight * 2); + return height; } return HeightCacheValue.GetAdditive(0); diff --git a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SelectDrawer.cs b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SelectDrawer.cs index f3d0370..e9f745e 100644 --- a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SelectDrawer.cs +++ b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SelectDrawer.cs @@ -24,7 +24,7 @@ protected override WrapperCollection GenerateCollection() protected override void DrawField(Rect position, SerializedProperty property, GUIContent label) { - if (_wrappers.TryGetValue(property, out var value) && value.Wrapper.SkipFieldDraw()) + if (_setupStrategy.SkipFieldDraw()) { var rect = PreparePropertyRect(position); // rect.height = value.Wrapper.GetHeight().Value; diff --git a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SelectDrawerBase.cs b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SelectDrawerBase.cs index d6b9557..f27d722 100644 --- a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SelectDrawerBase.cs +++ b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SelectDrawerBase.cs @@ -54,7 +54,17 @@ protected override bool PreDraw(ref Rect position, SerializedProperty property, { EditorGUI.BeginChangeCheck(); DrawField(position, property, label); - ExtendedGUIUtility.NotSupportedAttribute(position, property, label, GetFieldOrElementType(), _attribute.GetType()); + var offset = 0f; + if (_setupStrategy != null) + { + if (!_setupStrategy.SkipFieldDraw()) + { + var includeChildren = property.isExpanded; + offset = EditorGUI.GetPropertyHeight(property, includeChildren) + ExtendedGUIUtility.SpaceHeight; + } + } + + ExtendedGUIUtility.NotSupportedAttribute(position, property, label, GetFieldOrElementType(), _attribute.GetType(), offset); return false; } @@ -176,7 +186,8 @@ protected override HeightCacheValue GetPropertyHeight(SerializedProperty propert if (cache.Value == null) return HeightCacheValue.GetAdditive(0f); var selectWrapper = cache.Value.Wrapper; selectWrapper.Setup(property, _fieldInfo, _attribute, _setupStrategy); - return selectWrapper.GetHeight(); + var value = selectWrapper.GetHeight(); + return value; } var valueWrapper = cache.Value.Wrapper; @@ -185,7 +196,8 @@ protected override HeightCacheValue GetPropertyHeight(SerializedProperty propert valueWrapper.Setup(property, _fieldInfo, _attribute, _setupStrategy); } - return valueWrapper.GetHeight(); + var height = valueWrapper.GetHeight(); + return height; } private void InitializeSetupStrategy(SerializedProperty property, TAttribute attribute) diff --git a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/DropdownStrategy.cs b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/DropdownStrategy.cs index c365c65..067883a 100644 --- a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/DropdownStrategy.cs +++ b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/DropdownStrategy.cs @@ -30,6 +30,11 @@ public DropdownStrategy(FieldInfo fieldInfo, object propertyContainer, SelectAtt { _dropdownAttribute = (DropdownAttribute)selectAttributeBase; } + + public override bool SkipFieldDraw() + { + return true; + } private bool TryGetType(IEnumerable path, out Type type) { diff --git a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SelectEnumStrategy.cs b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SelectEnumStrategy.cs index b025a01..2f7ed21 100644 --- a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SelectEnumStrategy.cs +++ b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SelectEnumStrategy.cs @@ -36,6 +36,11 @@ public PredefinedValues(string name, int value) public int Value { get; } } + public override bool SkipFieldDraw() + { + return true; + } + public override string GetButtonName(object currentValue) { var intValue = (int)currentValue; diff --git a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SelectImplementationStrategy.cs b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SelectImplementationStrategy.cs index 154bb13..82dd17f 100644 --- a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SelectImplementationStrategy.cs +++ b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SelectImplementationStrategy.cs @@ -1,19 +1,39 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Reflection; using Better.Attributes.Runtime.Select; using Better.Commons.EditorAddons.Enums; using Better.Commons.EditorAddons.Extensions; -using Better.Commons.EditorAddons.Utility; +using Better.Commons.Runtime.Extensions; using UnityEngine; namespace Better.Attributes.EditorAddons.Drawers.Select.SetupStrategies { - public class SelectImplementationStrategy : SelectTypeStrategy + public class SelectImplementationStrategy : SelectSerializedTypeStrategy { public SelectImplementationStrategy(FieldInfo fieldInfo, object container, SelectAttributeBase selectAttributeBase) : base(fieldInfo, container, selectAttributeBase) { } + + public override List Setup() + { + var selectionObjects = GetFieldOrElementType().GetAllInheritedTypesWithoutUnityObject().Cast().ToList(); + selectionObjects.Insert(0, null); + return selectionObjects; + } + + public override bool SkipFieldDraw() + { + return false; + } + + public override bool CheckSupported() + { + var baseType = GetFieldOrElementType(); + return baseType.IsAbstract || baseType.IsInterface; + } public override GUIContent[] ResolveGroupedName(object value, DisplayGrouping grouping) { diff --git a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SelectTypeStrategy.cs b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SelectSerializedTypeStrategy.cs similarity index 92% rename from Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SelectTypeStrategy.cs rename to Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SelectSerializedTypeStrategy.cs index e25f659..18432ad 100644 --- a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SelectTypeStrategy.cs +++ b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SelectSerializedTypeStrategy.cs @@ -11,9 +11,14 @@ namespace Better.Attributes.EditorAddons.Drawers.Select.SetupStrategies { - public class SelectTypeStrategy : SetupStrategy + public class SelectSerializedTypeStrategy : SetupStrategy { - public SelectTypeStrategy(FieldInfo fieldInfo, object propertyContainer, SelectAttributeBase selectAttributeBase) : base(fieldInfo, propertyContainer, + public override bool SkipFieldDraw() + { + return true; + } + + public SelectSerializedTypeStrategy(FieldInfo fieldInfo, object propertyContainer, SelectAttributeBase selectAttributeBase) : base(fieldInfo, propertyContainer, selectAttributeBase) { } @@ -55,7 +60,7 @@ public override bool Validate(object item) public override bool CheckSupported() { - return true; + return false; } public override GUIContent GenerateHeader() diff --git a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SelectTypeStrategy.cs.meta b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SelectSerializedTypeStrategy.cs.meta similarity index 100% rename from Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SelectTypeStrategy.cs.meta rename to Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SelectSerializedTypeStrategy.cs.meta diff --git a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SetupStrategy.cs b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SetupStrategy.cs index 0e24a56..59969cf 100644 --- a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SetupStrategy.cs +++ b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/SetupStrategies/SetupStrategy.cs @@ -28,6 +28,7 @@ protected SetupStrategy(FieldInfo fieldInfo, object propertyContainer, SelectAtt public abstract bool Validate(object item); public abstract bool CheckSupported(); public abstract GUIContent GenerateHeader(); + public abstract bool SkipFieldDraw(); public virtual Type GetFieldOrElementType() { diff --git a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/Wrappers/BaseSelectWrapper.cs b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/Wrappers/BaseSelectWrapper.cs index 9214350..cb4c5f9 100644 --- a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/Wrappers/BaseSelectWrapper.cs +++ b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/Wrappers/BaseSelectWrapper.cs @@ -3,8 +3,11 @@ using Better.Attributes.Runtime.Select; using Better.Commons.EditorAddons.Drawers.Caching; using Better.Commons.EditorAddons.Drawers.Utility; +using Better.Commons.EditorAddons.Enums; using Better.Commons.EditorAddons.Extensions; +using Better.Commons.EditorAddons.Utility; using Better.Commons.Runtime.Drawers.Attributes; +using Better.Commons.Runtime.Extensions; using UnityEditor; namespace Better.Attributes.EditorAddons.Drawers.Select.Wrappers @@ -16,30 +19,61 @@ public abstract class BaseSelectWrapper : UtilityWrapper protected MultiPropertyAttribute _attribute; protected SetupStrategy _setupStrategy; - public override void Deconstruct() + public virtual void Setup(SerializedProperty property, FieldInfo fieldInfo, MultiPropertyAttribute attribute, SetupStrategy setupStrategy) { - _property = null; + _property = property; + _fieldInfo = fieldInfo; + _attribute = attribute; + _setupStrategy = setupStrategy; } - public abstract bool SkipFieldDraw(); + public virtual HeightCacheValue GetHeight() + { + var copy = _property.Copy(); + var type = _fieldInfo.FieldType; + if (type.IsArrayOrList()) + { + type = type.GetCollectionElementType(); + } - public abstract HeightCacheValue GetHeight(); + var propertyHeight = GetPropertyHeight(copy); + if (_setupStrategy == null || !_setupStrategy.CheckSupported()) + { + var message = ExtendedGUIUtility.NotSupportedMessage(copy.name, type, _attribute.GetType()); + propertyHeight += ExtendedGUIUtility.GetHelpBoxHeight(EditorGUIUtility.currentViewWidth, message, IconType.ErrorMessage); + propertyHeight += ExtendedGUIUtility.SpaceHeight; + } - public abstract void Update(object value); + var full = HeightCacheValue.GetFull(propertyHeight); + copy.Dispose(); + return full; + } - public virtual void Setup(SerializedProperty property, FieldInfo fieldInfo, MultiPropertyAttribute attribute, SetupStrategy setupStrategy) + protected virtual float GetPropertyHeight(SerializedProperty copy) { - _property = property; - _fieldInfo = fieldInfo; - _attribute = attribute; - _setupStrategy = setupStrategy; + var includeChildren = !_setupStrategy.SkipFieldDraw(); + var propertyHeight = 0f; + if (includeChildren) + { + includeChildren = copy.isExpanded; + propertyHeight = EditorGUI.GetPropertyHeight(copy, includeChildren); + } + + return propertyHeight; } + public abstract void Update(object value); + + public abstract object GetCurrentValue(); + public virtual bool Verify() { return _property.Verify(); } - public abstract object GetCurrentValue(); + public override void Deconstruct() + { + _property = null; + } } } \ No newline at end of file diff --git a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/Wrappers/DropdownWrapper.cs b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/Wrappers/DropdownWrapper.cs index 4028c0e..7127683 100644 --- a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/Wrappers/DropdownWrapper.cs +++ b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/Wrappers/DropdownWrapper.cs @@ -1,20 +1,9 @@ -using Better.Commons.EditorAddons.Drawers.Caching; -using Better.Commons.EditorAddons.Extensions; -using UnityEditor; +using Better.Commons.EditorAddons.Extensions; namespace Better.Attributes.EditorAddons.Drawers.Select.Wrappers { public class DropdownWrapper : BaseSelectWrapper { - public override bool SkipFieldDraw() - { - return true; - } - - public override HeightCacheValue GetHeight() - { - return HeightCacheValue.GetFull(EditorGUI.GetPropertyHeight(_property, false)); - } public override void Update(object value) { diff --git a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/Wrappers/SelectEnumWrapper.cs b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/Wrappers/SelectEnumWrapper.cs index 7a64f8e..dd5521c 100644 --- a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/Wrappers/SelectEnumWrapper.cs +++ b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/Wrappers/SelectEnumWrapper.cs @@ -4,7 +4,9 @@ using Better.Attributes.EditorAddons.Extensions; using Better.Attributes.Runtime.Select; using Better.Commons.EditorAddons.Drawers.Caching; +using Better.Commons.EditorAddons.Enums; using Better.Commons.EditorAddons.Extensions; +using Better.Commons.EditorAddons.Utility; using Better.Commons.Runtime.Drawers.Attributes; using Better.Commons.Runtime.Extensions; using Better.Commons.Runtime.Utility; @@ -17,17 +19,6 @@ public class SelectEnumWrapper : BaseSelectWrapper private bool _isFlag; private int _everythingValue; - public override bool SkipFieldDraw() - { - return true; - } - - public override HeightCacheValue GetHeight() - { - var heightCacheValue = HeightCacheValue.GetFull(EditorGUI.GetPropertyHeight(_property, false)); - return heightCacheValue; - } - public override void Setup(SerializedProperty property, FieldInfo fieldInfo, MultiPropertyAttribute attribute, SetupStrategy setupStrategy) { base.Setup(property, fieldInfo, attribute, setupStrategy); @@ -36,10 +27,16 @@ public override void Setup(SerializedProperty property, FieldInfo fieldInfo, Mul { enumType = enumType.GetCollectionElementType(); } + _everythingValue = EnumUtility.EverythingFlag(enumType).ToFlagInt(); _isFlag = fieldInfo.FieldType.GetCustomAttribute() != null; } + protected override float GetPropertyHeight(SerializedProperty copy) + { + return EditorGUI.GetPropertyHeight(copy, true); + } + public override void Update(object objValue) { if (!_property.Verify()) return; @@ -49,7 +46,7 @@ public override void Update(object objValue) _property.intValue = currentValue; } - + public override object GetCurrentValue() { return _property.intValue; diff --git a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/Wrappers/SelectSerializedTypeWrapper.cs b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/Wrappers/SelectSerializedTypeWrapper.cs index ed8d75d..9f0739a 100644 --- a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/Wrappers/SelectSerializedTypeWrapper.cs +++ b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/Wrappers/SelectSerializedTypeWrapper.cs @@ -1,5 +1,4 @@ using System; -using Better.Commons.EditorAddons.Drawers.Caching; using Better.Commons.EditorAddons.Extensions; using Better.Commons.Runtime.DataStructures.SerializedTypes; using UnityEditor; @@ -8,16 +7,6 @@ namespace Better.Attributes.EditorAddons.Drawers.Select.Wrappers { public class SelectSerializedTypeWrapper : BaseSelectWrapper { - public override bool SkipFieldDraw() - { - return true; - } - - public override HeightCacheValue GetHeight() - { - var full = HeightCacheValue.GetFull(EditorGUI.GetPropertyHeight(_property, false)); - return full; - } public override void Update(object value) { diff --git a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/Wrappers/SelectTypeWrapper.cs b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/Wrappers/SelectTypeWrapper.cs index c4b8ad7..48afb72 100644 --- a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/Wrappers/SelectTypeWrapper.cs +++ b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Select/Wrappers/SelectTypeWrapper.cs @@ -1,38 +1,10 @@ using System; -using Better.Attributes.EditorAddons.Drawers.Utility; -using Better.Commons.EditorAddons.Drawers.Caching; -using Better.Commons.EditorAddons.Enums; using Better.Commons.EditorAddons.Extensions; -using Better.Commons.EditorAddons.Utility; -using Better.Commons.Runtime.Extensions; -using UnityEditor; namespace Better.Attributes.EditorAddons.Drawers.Select.Wrappers { public class SelectTypeWrapper : BaseSelectWrapper { - public override bool SkipFieldDraw() - { - return false; - } - - public override HeightCacheValue GetHeight() - { - var type = _fieldInfo.FieldType; - if (type.IsArrayOrList()) - { - type = type.GetCollectionElementType(); - } - - var propertyHeight = EditorGUI.GetPropertyHeight(_property, true); - if (!_setupStrategy.CheckSupported()) - { - var message = ExtendedGUIUtility.NotSupportedMessage(_property.name, type, _attribute.GetType()); - propertyHeight += ExtendedGUIUtility.GetHelpBoxHeight(EditorGUIUtility.currentViewWidth, message, IconType.ErrorMessage); - } - var full = HeightCacheValue.GetFull(propertyHeight); - return full; - } public override void Update(object value) { diff --git a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Utility/SelectUtility.cs b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Utility/SelectUtility.cs index c600217..7b3e46b 100644 --- a/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Utility/SelectUtility.cs +++ b/Assets/BetterAttributes/Editor/EditorAddons/Drawers/Utility/SelectUtility.cs @@ -32,7 +32,7 @@ public SelectUtility() { typeof(SelectAttribute), new Dictionary(TypeComparer.Instance) { - { typeof(SerializedType), typeof(SelectTypeStrategy) }, + { typeof(SerializedType), typeof(SelectSerializedTypeStrategy) }, { typeof(Enum), typeof(SelectEnumStrategy) }, { typeof(Type), typeof(SelectImplementationStrategy) } } diff --git a/Assets/BetterAttributes/Runtime/Attributes/Misc/CustomTooltipAttribute.cs b/Assets/BetterAttributes/Runtime/Attributes/Misc/CustomTooltipAttribute.cs index 33052fb..dbb3ddc 100644 --- a/Assets/BetterAttributes/Runtime/Attributes/Misc/CustomTooltipAttribute.cs +++ b/Assets/BetterAttributes/Runtime/Attributes/Misc/CustomTooltipAttribute.cs @@ -15,6 +15,7 @@ public class CustomTooltipAttribute : MiscAttribute public CustomTooltipAttribute(string tooltip) { Tooltip = tooltip; + order = -999; } } } \ No newline at end of file diff --git a/Assets/BetterAttributes/Samples~/TestSamples/Scripts/Test.cs b/Assets/BetterAttributes/Samples~/TestSamples/Scripts/Test.cs index 2f52be3..5f35024 100644 --- a/Assets/BetterAttributes/Samples~/TestSamples/Scripts/Test.cs +++ b/Assets/BetterAttributes/Samples~/TestSamples/Scripts/Test.cs @@ -59,91 +59,91 @@ public class Test : MonoBehaviour { [HideLabel] [Select(typeof(ISomeInterface))] [SerializeField] private SerializedType serializedType; - + [Select] [SerializeField] private KeyCode keyCode; - + [DisableIf(nameof(keyCode), KeyCode.D)] [Select] [SerializeField] private MyFlagEnum myFlagEnumTest; - + [EnumButtons] [HideLabel] [SerializeField] private TestEnum myEnumTest; - + [ShowIf(nameof(keyCode), KeyCode.Backspace)] [Preview] [DrawInspector] [SerializeField] private PreviewTest component; - + [Preview] [CustomTooltip("Test tooltip")] [SerializeField] private Texture2D texture; - + [HelpBox("It's help box")] [DrawInspector] [SerializeField] private List scriptableObjectList; - + [DrawInspector] [SerializeField] private TestScriptableObject[] scriptableObjectArray; [DrawInspector] [SerializeField] private TestScriptableObject scriptableObject; - + [GizmoLocal] [SerializeField] private Vector3 vector3Local; - + [GizmoLocal] [RenameField("Quaternion Local Rename")] [SerializeField] private Quaternion quaternion; - + [GizmoLocal] [SerializeField] private SomeClass some; - + [HideLabel] [SerializeField] private SomeClass someClass; - + [ReadOnly] [SerializeField] private float someFloat; - + [Select(DisplayGrouping.GroupedFlat)] [SerializeReference] private ISomeInterface someInterface; - + [Select] [SerializeReference] private SomeAbstractClass someAbstractClass; - + [Select(typeof(SomeAbstractClass), DisplayName.Full)] [SerializeReference] private List someAbstractClasses; - + [Select(typeof(ISomeInterface), DisplayGrouping.Grouped)] [SerializeReference] private List someInterfaces; - + [GizmoLocal] [SerializeField] private Bounds bounds; - + [DisableInEditorMode] [SerializeField] private List _vector3s; - + [ShowInEditorMode] [SerializeField] private int showInEditorMode; - + [HideInEditorMode] [SerializeField] private int hideInEditorMode; - + [HideInPlayMode] [SerializeField] private int hideInPlayMode; - + [ShowInPlayMode] [SerializeField] private int showInPlayMode; - + [EnableInPlayMode] [SerializeField] private int enableInPlayMode; - + [DisableInEditorMode] [SerializeField] private int disableInEditorMode; - + [EnableInEditorMode] [SerializeField] private int enableInEditorMode; - + [DisableInPlayMode] [SerializeField] private int disableInPlayMode; - + [SerializeField] private bool boolField; - + [ShowIf(nameof(boolField), true)] [SerializeField] private int showIfBool; - + [HideIf(nameof(boolField), true)] [SerializeField] private int hideIfBool; - + [DisableIf(nameof(boolField), true)] [SerializeField] private int disableIfBool; - + [EnableIf(nameof(boolField), true)] [SerializeField] private int enableIfBool; - - + + ///Default usage of attribute. [EditorButton] private void SomeMethod() { //Some code. } - + ///This button will call method with predefined parameters. ///When invokeParams not specified will call with null. [EditorButton(InvokeParams = new object[] { 10f })] @@ -151,7 +151,7 @@ private void SomeMethod(float floatValue) { Debug.Log($"{nameof(SomeMethod)}({floatValue})"); } - + ///This button will call method with predefined parameters. ///When invokeParams not specified will call with null. [EditorButton(InvokeParams = new object[] { 10f, 10 })] @@ -159,7 +159,7 @@ private void SomeMethod(float floatValue, int intValue) { Debug.Log($"{nameof(SomeMethod)}({floatValue}, {intValue})"); } - + /// This button will be in the same row with button for SomeMethod2. /// But will be in the second position. /// When captureGroup not specified each button placed in separate row. @@ -169,13 +169,13 @@ private void SomeMethod1() { Debug.Log($"{nameof(SomeMethod1)}"); } - + [EditorButton(CaptureGroup = 1, Priority = 1)] private void SomeMethod2() { Debug.Log($"{nameof(SomeMethod2)}"); } - + /// This button will have name "Some Cool Button". /// When displayName not specified or null/empty/whitespace button /// will have name same as method. diff --git a/Assets/BetterAttributes/package.json b/Assets/BetterAttributes/package.json index 1524353..58bac2e 100644 --- a/Assets/BetterAttributes/package.json +++ b/Assets/BetterAttributes/package.json @@ -5,7 +5,7 @@ "unity": "2021.3", "description": "Unity attributes, allows to serialize interfaces, draw handles for Vector3/Vector2/Quaternion/Bounds, create read only fields.", "dependencies": { - "com.tdw.better.commons" : "0.0.2", + "com.tdw.better.commons" : "0.0.3", "com.tdw.better.internal.core" : "0.0.2" }, "author": { diff --git a/Packages/manifest.json b/Packages/manifest.json index 87d4ab7..b189c57 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -1,6 +1,6 @@ { "dependencies": { - "com.tdw.better.commons": "0.0.2", + "com.tdw.better.commons": "0.0.3", "com.unity.ai.navigation": "1.1.4", "com.unity.collab-proxy": "2.0.7", "com.unity.ide.rider": "3.0.24", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 860ad37..935f827 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -1,7 +1,7 @@ { "dependencies": { "com.tdw.better.commons": { - "version": "0.0.2", + "version": "0.0.3", "depth": 0, "source": "registry", "dependencies": {