From 7b58201b1225ff4df247c13e3894dcf929fb7e09 Mon Sep 17 00:00:00 2001 From: Bruno Mikoski Date: Fri, 30 Aug 2024 15:07:16 +0100 Subject: [PATCH] fix: items not being saved without ApplyModifiedProperties() --- CHANGELOG.MD | 6 ++++++ .../CollectionItemIndirectReferencePropertyDrawer.cs | 12 ++++++------ .../CollectionItemPickerPropertyDrawer.cs | 4 ++++ .../PropertyDrawers/CollectionItemPropertyDrawer.cs | 1 + 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 13c9ef0..89e22e6 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [2.3.5] +## Changed +- Added `ApplyModifiedProperties()` to property drawers again, since was causing issues with the shareable picker. This was removed on [2.3.4] + + ## [2.3.4] ## Changed - Update PickerPropertyDrawer to use PopupList from property path cache to avoid issue when rendered inside a List/Array @@ -582,6 +587,7 @@ public bool IsValidConsumable(Consumable consumable) ### Added - First initial working version +[2.3.5]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v2.3.5~~~~ [2.3.4]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v2.3.4 [2.3.3]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v2.3.3 [2.3.2]: https://github.com/badawe/ScriptableObjectCollection/releases/tag/v2.3.2 diff --git a/Scripts/Editor/PropertyDrawers/CollectionItemIndirectReferencePropertyDrawer.cs b/Scripts/Editor/PropertyDrawers/CollectionItemIndirectReferencePropertyDrawer.cs index 1842ddc..2ebe91d 100644 --- a/Scripts/Editor/PropertyDrawers/CollectionItemIndirectReferencePropertyDrawer.cs +++ b/Scripts/Editor/PropertyDrawers/CollectionItemIndirectReferencePropertyDrawer.cs @@ -64,18 +64,17 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten if (collectionItemPropertyDrawer.OptionsAttribute.DrawType == DrawType.Dropdown) { - DrawItemDrawer(position, property, label, collectionItem); + collectionItemPropertyDrawer.DrawCollectionItemDrawer(ref position, property, collectionItem, label, item => + { + SetSerializedPropertyGUIDs(item); + drawingProperty.serializedObject.ApplyModifiedProperties(); + }); return; } EditorGUI.PropertyField(position, property, label, true); } - private void DrawItemDrawer(Rect position, SerializedProperty property, GUIContent label, ScriptableObject collectionItem) - { - collectionItemPropertyDrawer.DrawCollectionItemDrawer(ref position, property, collectionItem, label, SetSerializedPropertyGUIDs); - } - private void SetSerializedPropertyGUIDs(ScriptableObject item) { if (item == null) @@ -103,6 +102,7 @@ private void SetSerializedPropertyGUIDs(ScriptableObject item) collectionLastKnowNameSerializedProperty.stringValue = socItem.Collection.name; } } + } private bool TryGetCollectionItem(out ScriptableObject item) diff --git a/Scripts/Editor/PropertyDrawers/CollectionItemPickerPropertyDrawer.cs b/Scripts/Editor/PropertyDrawers/CollectionItemPickerPropertyDrawer.cs index de558ae..bb24ad3 100644 --- a/Scripts/Editor/PropertyDrawers/CollectionItemPickerPropertyDrawer.cs +++ b/Scripts/Editor/PropertyDrawers/CollectionItemPickerPropertyDrawer.cs @@ -187,6 +187,8 @@ private void GetValuesFromPopup(PopupList popupList, SerializedProper propertyArrayIndex++; } } + + itemsProperty.serializedObject.ApplyModifiedProperties(); } private void AssignItemGUIDToProperty(ScriptableObject scriptableObject, SerializedProperty newProperty) @@ -246,6 +248,8 @@ private void SetSelectedValuesOnPopup(PopupList popupList, Serialized itemsProperty.DeleteArrayElementAtIndex(i); } } + + itemsProperty.serializedObject.ApplyModifiedProperties(); } private LongGuid GetGUIDFromProperty(SerializedProperty property) diff --git a/Scripts/Editor/PropertyDrawers/CollectionItemPropertyDrawer.cs b/Scripts/Editor/PropertyDrawers/CollectionItemPropertyDrawer.cs index 267ac79..c444106 100644 --- a/Scripts/Editor/PropertyDrawers/CollectionItemPropertyDrawer.cs +++ b/Scripts/Editor/PropertyDrawers/CollectionItemPropertyDrawer.cs @@ -102,6 +102,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten newItem => { property.objectReferenceValue = newItem; + property.serializedObject.ApplyModifiedProperties(); }); } EditorGUI.EndProperty();