Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 7342ed2

Browse files
Merged in fix/Transferableclones (pull request #98)
tems marked as transferable, remain transferable after being dropped
2 parents afe7598 + 7929023 commit 7342ed2

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

Runtime/Scripts/Controls/ReorderableList/ReorderableList.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,7 @@ Canvas GetCanvas()
8989
/// </summary>
9090
public void Refresh()
9191
{
92-
93-
_listContent = ContentLayout.gameObject.GetComponent<ReorderableListContent>();
94-
95-
if (!_listContent)
96-
{
97-
_listContent = ContentLayout.gameObject.AddComponent<ReorderableListContent>();
98-
}
99-
92+
_listContent = ContentLayout.gameObject.GetOrAddComponent<ReorderableListContent>();
10093
_listContent.Init(this);
10194
}
10295

Runtime/Scripts/Controls/ReorderableList/ReorderableListDebug.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private void ElementDropped(ReorderableList.ReorderableListEventStruct droppedSt
2323
if (droppedStruct.IsAClone)
2424
DebugLabel.text += "Source Object: " + droppedStruct.SourceObject.name + "\n";
2525
DebugLabel.text += string.Format("From {0} at Index {1} \n", droppedStruct.FromList.name, droppedStruct.FromIndex);
26-
DebugLabel.text += string.Format("To {0} at Index {1} \n", droppedStruct.ToList.name, droppedStruct.ToIndex);
26+
DebugLabel.text += string.Format("To {0} at Index {1} \n", droppedStruct.ToList == null ? "Empty space" : droppedStruct.ToList.name, droppedStruct.ToIndex);
2727
}
2828
}
2929
}

Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,28 @@ namespace UnityEngine.UI.Extensions
1313
public class ReorderableListElement : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
1414
{
1515
[Tooltip("Can this element be dragged?")]
16-
public bool IsGrabbable = true;
16+
[SerializeField]
17+
private bool IsGrabbable = true;
18+
1719
[Tooltip("Can this element be transfered to another list")]
18-
public bool IsTransferable = true;
20+
[SerializeField]
21+
private bool _isTransferable = true;
22+
1923
[Tooltip("Can this element be dropped in space?")]
20-
public bool isDroppableInSpace = false;
24+
[SerializeField]
25+
private bool isDroppableInSpace = false;
26+
2127

28+
public bool IsTransferable
29+
{
30+
get { return _isTransferable; }
31+
set
32+
{
33+
_canvasGroup = gameObject.GetOrAddComponent<CanvasGroup>();
34+
_canvasGroup.blocksRaycasts = value;
35+
_isTransferable = value;
36+
}
37+
}
2238

2339
private readonly List<RaycastResult> _raycastResults = new List<RaycastResult>();
2440
private ReorderableList _currentReorderableListRaycasted;
@@ -48,6 +64,7 @@ public class ReorderableListElement : MonoBehaviour, IDragHandler, IBeginDragHan
4864

4965
public void OnBeginDrag(PointerEventData eventData)
5066
{
67+
if (!_canvasGroup) { _canvasGroup = gameObject.GetOrAddComponent<CanvasGroup>(); }
5168
_canvasGroup.blocksRaycasts = false;
5269
isValid = true;
5370
if (_reorderableList == null)
@@ -162,7 +179,7 @@ public void OnDrag(PointerEventData eventData)
162179

163180
//If nothing found or the list is not dropable, put the fake element outside
164181
if (_currentReorderableListRaycasted == null || _currentReorderableListRaycasted.IsDropable == false
165-
|| (_oldReorderableListRaycasted != _reorderableList && !IsTransferable)
182+
// || (_oldReorderableListRaycasted != _reorderableList && !IsTransferable)
166183
|| ((_fakeElement.parent == _currentReorderableListRaycasted.Content
167184
? _currentReorderableListRaycasted.Content.childCount - 1
168185
: _currentReorderableListRaycasted.Content.childCount) >= _currentReorderableListRaycasted.maxItems && !_currentReorderableListRaycasted.IsDisplacable)
@@ -378,13 +395,19 @@ public void OnEndDrag(PointerEventData eventData)
378395
_draggingObject.SetParent(_currentReorderableListRaycasted.Content, false);
379396
_draggingObject.rotation = _currentReorderableListRaycasted.transform.rotation;
380397
_draggingObject.SetSiblingIndex(_fakeElement.GetSiblingIndex());
398+
399+
//If the item is transferable, it can be dragged out again
400+
if (IsTransferable)
401+
{
402+
var cg = _draggingObject.GetComponent<CanvasGroup>();
403+
cg.blocksRaycasts = true;
404+
}
381405
// Force refreshing both lists because otherwise we get inappropriate FromList in ReorderableListEventStruct
382406
_reorderableList.Refresh();
383407
_currentReorderableListRaycasted.Refresh();
384408

385409
_reorderableList.OnElementAdded.Invoke(args);
386-
387-
410+
388411
if (_displacedObject != null)
389412
{
390413
finishDisplacingElement();

0 commit comments

Comments
 (0)