diff --git a/Editor/Extensions/SerializedPropertyExtension.cs b/Editor/Extensions/SerializedPropertyExtension.cs index b11ab03..e249e20 100644 --- a/Editor/Extensions/SerializedPropertyExtension.cs +++ b/Editor/Extensions/SerializedPropertyExtension.cs @@ -495,6 +495,10 @@ namespace Module.Inspector.Editor switch (property.propertyType) { case SerializedPropertyType.Generic: + #if UNITY_6000_0_OR_NEWER + if (property.boxedValue != null) + return property.boxedValue.ToString(); + #endif break; case SerializedPropertyType.Integer: return property.intValue.ToString(); diff --git a/Editor/Predrawers/FieldLabelFromToStringAttributeDrawer.cs b/Editor/Predrawers/FieldLabelFromToStringAttributeDrawer.cs new file mode 100644 index 0000000..9fce5bc --- /dev/null +++ b/Editor/Predrawers/FieldLabelFromToStringAttributeDrawer.cs @@ -0,0 +1,14 @@ +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(FieldLabelFromToStringAttribute))] + internal sealed class FieldLabelFromToStringAttributeDrawer : PredrawerModifierPropertyDrawer + { + public override void Modify(PredrawerModifierPropertyAttribute attribute, SerializedProperty property, GUIContent label) + { + label.text = property.GetValueAsString(); + } + } +} \ No newline at end of file diff --git a/Editor/Predrawers/FieldLabelFromToStringAttributeDrawer.cs.meta b/Editor/Predrawers/FieldLabelFromToStringAttributeDrawer.cs.meta new file mode 100644 index 0000000..5833b76 --- /dev/null +++ b/Editor/Predrawers/FieldLabelFromToStringAttributeDrawer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: fddc7fa044dd4274a5776da1af9caaa9 +timeCreated: 1732461982 \ No newline at end of file diff --git a/README.md b/README.md index f9cbcbc..a89429d 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,8 @@ List of all available pre-drawer attributes: * Sets GUIContent label for `SerializedProperty` to enum name value of array index in parent field * `FieldLabelFromType` * Sets GUIContent label for `SerializedProperty` to value type from another field +* `FieldLabelFromToString` + * Sets GUIContent label for `SerializedProperty` to values ToString-method * `HideLabel` * Sets GUIContent label for `SerializedProperty` to empty string diff --git a/Runtime/Predrawers/FieldLabelFromToStringAttribute.cs b/Runtime/Predrawers/FieldLabelFromToStringAttribute.cs new file mode 100644 index 0000000..5e99ae4 --- /dev/null +++ b/Runtime/Predrawers/FieldLabelFromToStringAttribute.cs @@ -0,0 +1,12 @@ +using System; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class FieldLabelFromToStringAttribute : PredrawerModifierPropertyAttribute + { + public FieldLabelFromToStringAttribute() + { + } + } +} \ No newline at end of file diff --git a/Runtime/Predrawers/FieldLabelFromToStringAttribute.cs.meta b/Runtime/Predrawers/FieldLabelFromToStringAttribute.cs.meta new file mode 100644 index 0000000..c47e064 --- /dev/null +++ b/Runtime/Predrawers/FieldLabelFromToStringAttribute.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: da46777d3fc14716a8df225bca6c5b57 +timeCreated: 1732461953 \ No newline at end of file diff --git a/package.json b/package.json index 176c998..e123fcb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.module.inspector", - "version": "1.10.0", + "version": "1.11.0", "displayName": "Module.Inspector", "description": "Custom inspector with various useful property drawers", "unity": "2019.2",