diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 87d831d..4527601 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.0.2] +### Changed + - Updated Labels from `CollectionItemPicker` to use black as the default interface + - Added some helpers to help project upgrade + - Added `[DrawAsSOCItem]` attribute to allow drawing of `ScriptableObject, ISOCItem` as a regular CollectionItem, this is only necessary for unity versions bellow 2022, should not affect anything else. + ## [2.0.1] ### Changed - Refactored `CollectionItemPicker` to only use `LongGUID` and also the PropertyDrawer has been remade, now looks nicer 🤩 @@ -415,6 +421,7 @@ public bool IsValidConsumable(Consumable consumable) ### Added - First initial working version +[2.0.2]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v2.0.2 [2.0.1]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v2.0.1 [2.0.0]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v2.0.0 [1.9.7]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v1.9.7 diff --git a/Scripts/Editor/Core/PropertyDrawers/CollectionItemPickerPropertyDrawer.cs b/Scripts/Editor/Core/PropertyDrawers/CollectionItemPickerPropertyDrawer.cs index f6a0f37..43d2448 100644 --- a/Scripts/Editor/Core/PropertyDrawers/CollectionItemPickerPropertyDrawer.cs +++ b/Scripts/Editor/Core/PropertyDrawers/CollectionItemPickerPropertyDrawer.cs @@ -108,7 +108,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten if (item is ISOCColorizedItem coloredItem) GUI.backgroundColor = coloredItem.LabelColor; else - GUI.backgroundColor = originalColor; + GUI.backgroundColor = Color.black; GUI.Label(labelRect, labelContent, labelStyle); } diff --git a/Scripts/Editor/Core/PropertyDrawers/DrawAsSOCItemAttributePropertyDrawer.cs b/Scripts/Editor/Core/PropertyDrawers/DrawAsSOCItemAttributePropertyDrawer.cs new file mode 100644 index 0000000..cba64db --- /dev/null +++ b/Scripts/Editor/Core/PropertyDrawers/DrawAsSOCItemAttributePropertyDrawer.cs @@ -0,0 +1,28 @@ +#if !UNITY_2022_2_OR_NEWER +using System; +using UnityEditor; +using UnityEngine; + +namespace BrunoMikoski.ScriptableObjectCollections +{ + [CustomPropertyDrawer(typeof(DrawAsSOCItemAttribute))] + public class DrawAsSOCItemAttributePropertyDrawer : PropertyDrawer + { + private SOCItemPropertyDrawer socItemPropertyDrawer; + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + if (!typeof(ISOCItem).IsAssignableFrom(fieldInfo.FieldType)) + throw new Exception("[DrawAsSOCItem] should only be used on ScriptableObjects that implements the ISOCItem interface"); + + if (socItemPropertyDrawer == null) + { + socItemPropertyDrawer = new SOCItemPropertyDrawer(); + socItemPropertyDrawer.OverrideFieldInfo(fieldInfo); + } + + socItemPropertyDrawer.OnGUI(position, property, label); + } + } +} +#endif diff --git a/Scripts/Editor/Core/PropertyDrawers/DrawAsSOCItemAttributePropertyDrawer.cs.meta b/Scripts/Editor/Core/PropertyDrawers/DrawAsSOCItemAttributePropertyDrawer.cs.meta new file mode 100644 index 0000000..3b1356d --- /dev/null +++ b/Scripts/Editor/Core/PropertyDrawers/DrawAsSOCItemAttributePropertyDrawer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 765e1c72fdcf445b84854fa235a6054b +timeCreated: 1680708775 \ No newline at end of file diff --git a/Scripts/Editor/Core/PropertyDrawers/SOCItemPropertyDrawer.cs b/Scripts/Editor/Core/PropertyDrawers/SOCItemPropertyDrawer.cs index 4f79f60..8ac63e8 100644 --- a/Scripts/Editor/Core/PropertyDrawers/SOCItemPropertyDrawer.cs +++ b/Scripts/Editor/Core/PropertyDrawers/SOCItemPropertyDrawer.cs @@ -7,7 +7,11 @@ namespace BrunoMikoski.ScriptableObjectCollections { +#if UNITY_2022_2_OR_NEWER [CustomPropertyDrawer(typeof(ISOCItem), true)] +#else + [CustomPropertyDrawer(typeof(ScriptableObjectCollectionItem), true)] +#endif public class SOCItemPropertyDrawer : PropertyDrawer { public const float BUTTON_WIDTH = 30; @@ -24,12 +28,23 @@ private static readonly SOCItemEditorOptionsAttribute DefaultAttribute private CollectionItemDropdown collectionItemDropdown; private ScriptableObject item; private float totalHeight; + + private FieldInfo overrideFieldInfo; + private FieldInfo TargetFieldInfo + { + get + { + if (overrideFieldInfo == null) + return fieldInfo; + return overrideFieldInfo; + } + } private SOCItemEditorOptionsAttribute GetOptionsAttribute() { - if (fieldInfo == null) + if (TargetFieldInfo == null) return DefaultAttribute; - object[] attributes = fieldInfo.GetCustomAttributes(typeof(SOCItemEditorOptionsAttribute), false); + object[] attributes = TargetFieldInfo.GetCustomAttributes(typeof(SOCItemEditorOptionsAttribute), false); if (attributes.Length > 0) return attributes[0] as SOCItemEditorOptionsAttribute; return DefaultAttribute; @@ -139,15 +154,15 @@ private void Initialize(SerializedProperty property) return; Type itemType; - if (fieldInfo == null) + if (TargetFieldInfo == null) { Type parentType = property.serializedObject.targetObject.GetType(); itemType = property.GetFieldInfoFromPathByType(parentType).FieldType; } else { - Type arrayOrListType = fieldInfo.FieldType.GetArrayOrListType(); - itemType = arrayOrListType ?? fieldInfo.FieldType; + Type arrayOrListType = TargetFieldInfo.FieldType.GetArrayOrListType(); + itemType = arrayOrListType ?? TargetFieldInfo.FieldType; } Initialize(itemType, property.serializedObject.targetObject, GetOptionsAttribute()); @@ -199,7 +214,7 @@ private void DrawGotoButton(ref Rect popupRect, ScriptableObject collectionItem) if (!OptionsAttribute.ShouldDrawGotoButton) return; - if (!(collectionItem is ISOCItem socItem)) + if (collectionItem is not ISOCItem socItem) return; Rect buttonRect = popupRect; @@ -235,5 +250,10 @@ private void DrawEditFoldoutButton(ref Rect popupRect, ScriptableObject targetIt ObjectUtility.SetDirty(targetItem); } } + + public void OverrideFieldInfo(FieldInfo targetFieldInfo) + { + overrideFieldInfo = targetFieldInfo; + } } } diff --git a/Scripts/Runtime/Core/DrawAsSOCItemAttribute.cs b/Scripts/Runtime/Core/DrawAsSOCItemAttribute.cs new file mode 100644 index 0000000..0c6b3f7 --- /dev/null +++ b/Scripts/Runtime/Core/DrawAsSOCItemAttribute.cs @@ -0,0 +1,14 @@ +using System; +using UnityEngine; + +namespace BrunoMikoski.ScriptableObjectCollections +{ +#if UNITY_2022_2_OR_NEWER + [Obsolete("DrawAsSOCItemAttribute is not needed anymore, since Unity 2022 PropertyDrawers can be applied to interfaces")] +#endif + [AttributeUsage(AttributeTargets.Field)] + public class DrawAsSOCItemAttribute : PropertyAttribute + { + + } +} \ No newline at end of file diff --git a/Scripts/Runtime/Core/DrawAsSOCItemAttribute.cs.meta b/Scripts/Runtime/Core/DrawAsSOCItemAttribute.cs.meta new file mode 100644 index 0000000..61e71db --- /dev/null +++ b/Scripts/Runtime/Core/DrawAsSOCItemAttribute.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 382e5f3b7524429684dd50fd2892def2 +timeCreated: 1680709413 \ No newline at end of file diff --git a/Scripts/Runtime/Core/SOCItemEditorOptionsAttribute.cs b/Scripts/Runtime/Core/SOCItemEditorOptionsAttribute.cs index 55c9090..fe700c2 100644 --- a/Scripts/Runtime/Core/SOCItemEditorOptionsAttribute.cs +++ b/Scripts/Runtime/Core/SOCItemEditorOptionsAttribute.cs @@ -19,4 +19,10 @@ public class SOCItemEditorOptionsAttribute : Attribute public string ValidateMethod { get; set; } } + + //Temporary + [Obsolete("CollectionItemEditorOptions is deprecated, please use SOCItemEditorOptionsAttribute instead.")] + public class CollectionItemEditorOptions : SOCItemEditorOptionsAttribute + { + } } diff --git a/Scripts/Runtime/Core/ScriptableObjectCollectionItem.cs b/Scripts/Runtime/Core/ScriptableObjectCollectionItem.cs index f269717..aca401a 100644 --- a/Scripts/Runtime/Core/ScriptableObjectCollectionItem.cs +++ b/Scripts/Runtime/Core/ScriptableObjectCollectionItem.cs @@ -7,8 +7,6 @@ public class ScriptableObjectCollectionItem : ScriptableObject, IComparable