diff --git a/Scripts/Controls/ReorderableList/ReorderableList.cs b/Scripts/Controls/ReorderableList/ReorderableList.cs index 30e256e..c010421 100644 --- a/Scripts/Controls/ReorderableList/ReorderableList.cs +++ b/Scripts/Controls/ReorderableList/ReorderableList.cs @@ -28,6 +28,10 @@ namespace UnityEngine.UI.Extensions [Tooltip("Should dropped items displace a current item if the list is full?\n " + "Depending on the dropped items origin list, the displaced item may be added, dropped in space or deleted.")] public bool IsDisplacable = false; + + // This sets every item size (when being dragged over this list) to the current size of the first element of this list + [Tooltip("Should items being dragged over this list have their sizes equalized?")] + public bool EqualizeSizesOnDrag = false; public int maxItems = int.MaxValue; @@ -41,6 +45,7 @@ namespace UnityEngine.UI.Extensions public ReorderableListHandler OnElementDisplacedTo = new ReorderableListHandler(); public ReorderableListHandler OnElementDisplacedFromReturned = new ReorderableListHandler(); public ReorderableListHandler OnElementDisplacedToReturned = new ReorderableListHandler(); + public ReorderableListHandler OnElementDroppedWithMaxItems = new ReorderableListHandler(); private RectTransform _content; private ReorderableListContent _listContent; diff --git a/Scripts/Controls/ReorderableList/ReorderableListElement.cs b/Scripts/Controls/ReorderableList/ReorderableListElement.cs index 4c227fe..adcee13 100644 --- a/Scripts/Controls/ReorderableList/ReorderableListElement.cs +++ b/Scripts/Controls/ReorderableList/ReorderableListElement.cs @@ -392,12 +392,11 @@ namespace UnityEngine.UI.Extensions if (!isValid) throw new Exception("It's too late to cancel the Transfer! Do so in OnElementDropped!"); - - } - //We don't have an ReorderableList + else { + //We don't have an ReorderableList if (this.isDroppableInSpace) { _reorderableList.OnElementDropped.Invoke(new ReorderableList.ReorderableListEventStruct @@ -414,6 +413,29 @@ namespace UnityEngine.UI.Extensions { CancelDrag(); } + + //If there is no more room for the element in the target list, notify it (OnElementDroppedWithMaxItems event) + if (_currentReorderableListRaycasted != null) + { + if ((_currentReorderableListRaycasted.Content.childCount >= + _currentReorderableListRaycasted.maxItems && + !_currentReorderableListRaycasted.IsDisplacable) + || _currentReorderableListRaycasted.maxItems <= 0) + { + GameObject o = _draggingObject.gameObject; + _reorderableList.OnElementDroppedWithMaxItems.Invoke( + new ReorderableList.ReorderableListEventStruct + { + DroppedObject = o, + IsAClone = _reorderableList.CloneDraggedObject, + SourceObject = _reorderableList.CloneDraggedObject ? gameObject : o, + FromList = _reorderableList, + ToList = _currentReorderableListRaycasted, + FromIndex = _fromIndex + }); + } + } + } } @@ -483,7 +505,10 @@ namespace UnityEngine.UI.Extensions { Vector2 size = _draggingObjectOriginalSize; - if (_currentReorderableListRaycasted != null && _currentReorderableListRaycasted.IsDropable && _currentReorderableListRaycasted.Content.childCount > 0) + if (_currentReorderableListRaycasted != null + && _currentReorderableListRaycasted.IsDropable + && _currentReorderableListRaycasted.Content.childCount > 0 + && _currentReorderableListRaycasted.EqualizeSizesOnDrag) { var firstChild = _currentReorderableListRaycasted.Content.GetChild(0); if (firstChild != null)