Resolves #347
Items marked as transferable, remain transferable after being dropped Also fixed an issue with items that can be dropped in to space causing NRE with debug info.pull/413/head
parent
9b9aac4a74
commit
79290237b8
|
@ -89,14 +89,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Refresh()
|
public void Refresh()
|
||||||
{
|
{
|
||||||
|
_listContent = ContentLayout.gameObject.GetOrAddComponent<ReorderableListContent>();
|
||||||
_listContent = ContentLayout.gameObject.GetComponent<ReorderableListContent>();
|
|
||||||
|
|
||||||
if (!_listContent)
|
|
||||||
{
|
|
||||||
_listContent = ContentLayout.gameObject.AddComponent<ReorderableListContent>();
|
|
||||||
}
|
|
||||||
|
|
||||||
_listContent.Init(this);
|
_listContent.Init(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
if (droppedStruct.IsAClone)
|
if (droppedStruct.IsAClone)
|
||||||
DebugLabel.text += "Source Object: " + droppedStruct.SourceObject.name + "\n";
|
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("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
|
public class ReorderableListElement : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
|
||||||
{
|
{
|
||||||
[Tooltip("Can this element be dragged?")]
|
[Tooltip("Can this element be dragged?")]
|
||||||
public bool IsGrabbable = true;
|
[SerializeField]
|
||||||
[Tooltip("Can this element be transfered to another list")]
|
private bool IsGrabbable = true;
|
||||||
public bool IsTransferable = true;
|
|
||||||
[Tooltip("Can this element be dropped in space?")]
|
|
||||||
public bool isDroppableInSpace = false;
|
|
||||||
|
|
||||||
|
[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 readonly List<RaycastResult> _raycastResults = new List<RaycastResult>();
|
||||||
private ReorderableList _currentReorderableListRaycasted;
|
private ReorderableList _currentReorderableListRaycasted;
|
||||||
|
@ -48,6 +64,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
public void OnBeginDrag(PointerEventData eventData)
|
public void OnBeginDrag(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
|
if (!_canvasGroup) { _canvasGroup = gameObject.GetOrAddComponent<CanvasGroup>(); }
|
||||||
_canvasGroup.blocksRaycasts = false;
|
_canvasGroup.blocksRaycasts = false;
|
||||||
isValid = true;
|
isValid = true;
|
||||||
if (_reorderableList == null)
|
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 nothing found or the list is not dropable, put the fake element outside
|
||||||
if (_currentReorderableListRaycasted == null || _currentReorderableListRaycasted.IsDropable == false
|
if (_currentReorderableListRaycasted == null || _currentReorderableListRaycasted.IsDropable == false
|
||||||
|| (_oldReorderableListRaycasted != _reorderableList && !IsTransferable)
|
// || (_oldReorderableListRaycasted != _reorderableList && !IsTransferable)
|
||||||
|| ((_fakeElement.parent == _currentReorderableListRaycasted.Content
|
|| ((_fakeElement.parent == _currentReorderableListRaycasted.Content
|
||||||
? _currentReorderableListRaycasted.Content.childCount - 1
|
? _currentReorderableListRaycasted.Content.childCount - 1
|
||||||
: _currentReorderableListRaycasted.Content.childCount) >= _currentReorderableListRaycasted.maxItems && !_currentReorderableListRaycasted.IsDisplacable)
|
: _currentReorderableListRaycasted.Content.childCount) >= _currentReorderableListRaycasted.maxItems && !_currentReorderableListRaycasted.IsDisplacable)
|
||||||
|
@ -378,13 +395,19 @@ namespace UnityEngine.UI.Extensions
|
||||||
_draggingObject.SetParent(_currentReorderableListRaycasted.Content, false);
|
_draggingObject.SetParent(_currentReorderableListRaycasted.Content, false);
|
||||||
_draggingObject.rotation = _currentReorderableListRaycasted.transform.rotation;
|
_draggingObject.rotation = _currentReorderableListRaycasted.transform.rotation;
|
||||||
_draggingObject.SetSiblingIndex(_fakeElement.GetSiblingIndex());
|
_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
|
// Force refreshing both lists because otherwise we get inappropriate FromList in ReorderableListEventStruct
|
||||||
_reorderableList.Refresh();
|
_reorderableList.Refresh();
|
||||||
_currentReorderableListRaycasted.Refresh();
|
_currentReorderableListRaycasted.Refresh();
|
||||||
|
|
||||||
_reorderableList.OnElementAdded.Invoke(args);
|
_reorderableList.OnElementAdded.Invoke(args);
|
||||||
|
|
||||||
|
|
||||||
if (_displacedObject != null)
|
if (_displacedObject != null)
|
||||||
{
|
{
|
||||||
finishDisplacingElement();
|
finishDisplacingElement();
|
||||||
|
|
Loading…
Reference in New Issue