Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion Scripts/Editor/CustomEditors/CollectionCustomEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,17 @@ public class CollectionCustomEditor : BaseEditor<CollectionCustomEditor>

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
{
Expand All @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions Scripts/Editor/PropertyDrawers/SOCItemPropertyDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions Scripts/Runtime/Core/ScriptableObjectCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public void CopyTo(List<ScriptableObject> list)
public bool IsFixedSize => false;
public bool IsReadOnly => false;

public virtual bool ShouldProtectItemOrder => false;


public int Add(object value)
{
Expand Down