Merged in jesusmgg/unity-ui-extensions (pull request #50)

Added a new Event to ReorderableList: OnElementDroppedWithMaxItems.
pull/413/head
Jesús González 2019-04-10 14:01:34 +00:00 committed by Simon Jackson
commit d144c40a6b
2 changed files with 34 additions and 4 deletions

View File

@ -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;

View File

@ -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)