Merged in fix/Transferableclones (pull request #98)
tems marked as transferable, remain transferable after being droppedpull/413/head
commit
7342ed2e31
|
@ -89,14 +89,7 @@ namespace UnityEngine.UI.Extensions
|
|||
/// </summary>
|
||||
public void Refresh()
|
||||
{
|
||||
|
||||
_listContent = ContentLayout.gameObject.GetComponent<ReorderableListContent>();
|
||||
|
||||
if (!_listContent)
|
||||
{
|
||||
_listContent = ContentLayout.gameObject.AddComponent<ReorderableListContent>();
|
||||
}
|
||||
|
||||
_listContent = ContentLayout.gameObject.GetOrAddComponent<ReorderableListContent>();
|
||||
_listContent.Init(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace UnityEngine.UI.Extensions
|
|||
if (droppedStruct.IsAClone)
|
||||
DebugLabel.text += "Source Object: " + droppedStruct.SourceObject.name + "\n";
|
||||
DebugLabel.text += string.Format("From {0} at Index {1} \n", droppedStruct.FromList.name, droppedStruct.FromIndex);
|
||||
DebugLabel.text += string.Format("To {0} at Index {1} \n", droppedStruct.ToList.name, droppedStruct.ToIndex);
|
||||
DebugLabel.text += string.Format("To {0} at Index {1} \n", droppedStruct.ToList == null ? "Empty space" : droppedStruct.ToList.name, droppedStruct.ToIndex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,12 +13,28 @@ namespace UnityEngine.UI.Extensions
|
|||
public class ReorderableListElement : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
|
||||
{
|
||||
[Tooltip("Can this element be dragged?")]
|
||||
public bool IsGrabbable = true;
|
||||
[Tooltip("Can this element be transfered to another list")]
|
||||
public bool IsTransferable = true;
|
||||
[Tooltip("Can this element be dropped in space?")]
|
||||
public bool isDroppableInSpace = false;
|
||||
[SerializeField]
|
||||
private bool IsGrabbable = true;
|
||||
|
||||
[Tooltip("Can this element be transfered to another list")]
|
||||
[SerializeField]
|
||||
private bool _isTransferable = true;
|
||||
|
||||
[Tooltip("Can this element be dropped in space?")]
|
||||
[SerializeField]
|
||||
private bool isDroppableInSpace = false;
|
||||
|
||||
|
||||
public bool IsTransferable
|
||||
{
|
||||
get { return _isTransferable; }
|
||||
set
|
||||
{
|
||||
_canvasGroup = gameObject.GetOrAddComponent<CanvasGroup>();
|
||||
_canvasGroup.blocksRaycasts = value;
|
||||
_isTransferable = value;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly List<RaycastResult> _raycastResults = new List<RaycastResult>();
|
||||
private ReorderableList _currentReorderableListRaycasted;
|
||||
|
@ -48,6 +64,7 @@ namespace UnityEngine.UI.Extensions
|
|||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
if (!_canvasGroup) { _canvasGroup = gameObject.GetOrAddComponent<CanvasGroup>(); }
|
||||
_canvasGroup.blocksRaycasts = false;
|
||||
isValid = true;
|
||||
if (_reorderableList == null)
|
||||
|
@ -162,7 +179,7 @@ namespace UnityEngine.UI.Extensions
|
|||
|
||||
//If nothing found or the list is not dropable, put the fake element outside
|
||||
if (_currentReorderableListRaycasted == null || _currentReorderableListRaycasted.IsDropable == false
|
||||
|| (_oldReorderableListRaycasted != _reorderableList && !IsTransferable)
|
||||
// || (_oldReorderableListRaycasted != _reorderableList && !IsTransferable)
|
||||
|| ((_fakeElement.parent == _currentReorderableListRaycasted.Content
|
||||
? _currentReorderableListRaycasted.Content.childCount - 1
|
||||
: _currentReorderableListRaycasted.Content.childCount) >= _currentReorderableListRaycasted.maxItems && !_currentReorderableListRaycasted.IsDisplacable)
|
||||
|
@ -378,13 +395,19 @@ namespace UnityEngine.UI.Extensions
|
|||
_draggingObject.SetParent(_currentReorderableListRaycasted.Content, false);
|
||||
_draggingObject.rotation = _currentReorderableListRaycasted.transform.rotation;
|
||||
_draggingObject.SetSiblingIndex(_fakeElement.GetSiblingIndex());
|
||||
|
||||
//If the item is transferable, it can be dragged out again
|
||||
if (IsTransferable)
|
||||
{
|
||||
var cg = _draggingObject.GetComponent<CanvasGroup>();
|
||||
cg.blocksRaycasts = true;
|
||||
}
|
||||
// Force refreshing both lists because otherwise we get inappropriate FromList in ReorderableListEventStruct
|
||||
_reorderableList.Refresh();
|
||||
_currentReorderableListRaycasted.Refresh();
|
||||
|
||||
_reorderableList.OnElementAdded.Invoke(args);
|
||||
|
||||
|
||||
|
||||
if (_displacedObject != null)
|
||||
{
|
||||
finishDisplacingElement();
|
||||
|
|
Loading…
Reference in New Issue