diff --git a/Scripts/Editor/CustomEditors/CollectionCustomEditor.cs b/Scripts/Editor/CustomEditors/CollectionCustomEditor.cs index baa337e..35544ef 100644 --- a/Scripts/Editor/CustomEditors/CollectionCustomEditor.cs +++ b/Scripts/Editor/CustomEditors/CollectionCustomEditor.cs @@ -38,7 +38,17 @@ public class CollectionCustomEditor : BaseEditor private bool IsAutoGenerated => generatorType != null; - protected virtual bool CanBeReorderable => true; + protected virtual bool CanBeReorderable + { + get + { + // If we are supposed to protect the item order, do not allow items to be reordered by dragging. + if (collection != null && collection.ShouldProtectItemOrder) + return false; + + return true; + } + } protected virtual bool DisplayAddButton { @@ -60,6 +70,11 @@ protected virtual bool DisplayRemoveButton // doesn't make sense for you to remove items because they will be added back next time you generate. if (IsAutoGenerated && generator.ShouldRemoveNonGeneratedItems) return false; + + // If we are supposed to protect the item order, do not allow items to be removed, otherwise you could + // remove items from the middle and change the order. + if (collection != null && collection.ShouldProtectItemOrder) + return false; return true; } diff --git a/Scripts/Editor/PropertyDrawers/SOCItemPropertyDrawer.cs b/Scripts/Editor/PropertyDrawers/SOCItemPropertyDrawer.cs index 43c8fc2..fc3f39b 100644 --- a/Scripts/Editor/PropertyDrawers/SOCItemPropertyDrawer.cs +++ b/Scripts/Editor/PropertyDrawers/SOCItemPropertyDrawer.cs @@ -11,9 +11,8 @@ namespace BrunoMikoski.ScriptableObjectCollections { #if UNITY_2022_2_OR_NEWER [CustomPropertyDrawer(typeof(ISOCItem), true)] -#else - [CustomPropertyDrawer(typeof(ScriptableObjectCollectionItem), true)] #endif + [CustomPropertyDrawer(typeof(ScriptableObjectCollectionItem), true)] public class SOCItemPropertyDrawer : PropertyDrawer { private const float BUTTON_WIDTH = 30; diff --git a/Scripts/Runtime/Core/ScriptableObjectCollection.cs b/Scripts/Runtime/Core/ScriptableObjectCollection.cs index 25f8de0..4e7fa78 100644 --- a/Scripts/Runtime/Core/ScriptableObjectCollection.cs +++ b/Scripts/Runtime/Core/ScriptableObjectCollection.cs @@ -103,6 +103,8 @@ public void CopyTo(List list) public bool IsFixedSize => false; public bool IsReadOnly => false; + public virtual bool ShouldProtectItemOrder => false; + public int Add(object value) {