Added a new Event to ReorderableList: OnElementDroppedWithMaxItems.

It is called when an object is dropped on a ReorderableList with no more space left (currentItems >= maxItems).
pull/413/head
Jesús González 2019-04-09 20:35:34 -04:00
parent e0f5901dda
commit 93f9a314cf
2 changed files with 26 additions and 3 deletions

View File

@ -41,6 +41,7 @@ namespace UnityEngine.UI.Extensions
public ReorderableListHandler OnElementDisplacedTo = new ReorderableListHandler(); public ReorderableListHandler OnElementDisplacedTo = new ReorderableListHandler();
public ReorderableListHandler OnElementDisplacedFromReturned = new ReorderableListHandler(); public ReorderableListHandler OnElementDisplacedFromReturned = new ReorderableListHandler();
public ReorderableListHandler OnElementDisplacedToReturned = new ReorderableListHandler(); public ReorderableListHandler OnElementDisplacedToReturned = new ReorderableListHandler();
public ReorderableListHandler OnElementDroppedWithMaxItems = new ReorderableListHandler();
private RectTransform _content; private RectTransform _content;
private ReorderableListContent _listContent; private ReorderableListContent _listContent;

View File

@ -392,12 +392,11 @@ namespace UnityEngine.UI.Extensions
if (!isValid) if (!isValid)
throw new Exception("It's too late to cancel the Transfer! Do so in OnElementDropped!"); throw new Exception("It's too late to cancel the Transfer! Do so in OnElementDropped!");
} }
//We don't have an ReorderableList
else else
{ {
//We don't have an ReorderableList
if (this.isDroppableInSpace) if (this.isDroppableInSpace)
{ {
_reorderableList.OnElementDropped.Invoke(new ReorderableList.ReorderableListEventStruct _reorderableList.OnElementDropped.Invoke(new ReorderableList.ReorderableListEventStruct
@ -414,6 +413,29 @@ namespace UnityEngine.UI.Extensions
{ {
CancelDrag(); 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
});
}
}
} }
} }