Testing complete for Re-Orderable Lists
Added Editor Menus --HG-- branch : develop_5.2pull/413/head
parent
a88c7a9c1b
commit
5bd1751993
File diff suppressed because it is too large
Load Diff
|
@ -6,19 +6,28 @@ using UnityEngine.Events;
|
||||||
|
|
||||||
namespace UnityEngine.UI.Extensions
|
namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
|
[RequireComponent(typeof(RectTransform)), DisallowMultipleComponent]
|
||||||
[AddComponentMenu("UI/Extensions/Re-orderable list")]
|
[AddComponentMenu("UI/Extensions/Re-orderable list")]
|
||||||
public class ReorderableList : MonoBehaviour
|
public class ReorderableList : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
[Tooltip("Child container with re-orderable items in a layout group")]
|
||||||
public LayoutGroup ContentLayout;
|
public LayoutGroup ContentLayout;
|
||||||
|
[Tooltip("Parent area to draw the dragged element on top of containers. Defaults to the root Canvas")]
|
||||||
public bool IsDraggable = true;
|
|
||||||
public RectTransform DraggableArea;
|
public RectTransform DraggableArea;
|
||||||
|
|
||||||
|
[Tooltip("Can items be dragged from the container?")]
|
||||||
|
public bool IsDraggable = true;
|
||||||
|
[Tooltip("Should the draggable components be removed or cloned?")]
|
||||||
public bool CloneDraggedObject = false;
|
public bool CloneDraggedObject = false;
|
||||||
|
|
||||||
|
[Tooltip("Can new draggable items be dropped in to the container?")]
|
||||||
public bool IsDropable = true;
|
public bool IsDropable = true;
|
||||||
|
|
||||||
|
|
||||||
|
[Header("UI Re-orderable Events")]
|
||||||
public ReorderableListHandler OnElementDropped = new ReorderableListHandler();
|
public ReorderableListHandler OnElementDropped = new ReorderableListHandler();
|
||||||
|
public ReorderableListHandler OnElementGrabbed = new ReorderableListHandler();
|
||||||
|
public ReorderableListHandler OnElementRemoved = new ReorderableListHandler();
|
||||||
|
|
||||||
private RectTransform _content;
|
private RectTransform _content;
|
||||||
private ReorderableListContent _listContent;
|
private ReorderableListContent _listContent;
|
||||||
|
@ -37,14 +46,19 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (ContentLayout == null)
|
if (ContentLayout == null)
|
||||||
{
|
{
|
||||||
Debug.LogError("You need to have a LayoutGroup content set for the list", gameObject);
|
Debug.LogError("You need to have a child LayoutGroup content set for the list: " + name, gameObject);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (DraggableArea == null)
|
if (DraggableArea == null)
|
||||||
{
|
{
|
||||||
Debug.LogError("You need to set a draggable area for the list", gameObject);
|
DraggableArea = transform.root.GetComponentInChildren<Canvas>().GetComponent<RectTransform>();
|
||||||
|
}
|
||||||
|
if (IsDropable && !GetComponent<Graphic>())
|
||||||
|
{
|
||||||
|
Debug.LogError("You need to have a Graphic control (such as an Image) for the list [" + name + "] to be droppable", gameObject);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_listContent = ContentLayout.gameObject.AddComponent<ReorderableListContent>();
|
_listContent = ContentLayout.gameObject.AddComponent<ReorderableListContent>();
|
||||||
|
@ -56,7 +70,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public struct ReorderableListEventStruct
|
public struct ReorderableListEventStruct
|
||||||
{
|
{
|
||||||
public GameObject DropedObject;
|
public GameObject DroppedObject;
|
||||||
public int FromIndex;
|
public int FromIndex;
|
||||||
public ReorderableList FromList;
|
public ReorderableList FromList;
|
||||||
public bool IsAClone;
|
public bool IsAClone;
|
||||||
|
@ -74,6 +88,12 @@ namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void TestReOrderableListTarget(ReorderableListEventStruct item)
|
||||||
|
{
|
||||||
|
Debug.Log("Event Received");
|
||||||
|
Debug.Log("Hello World, is my item a clone? [" + item.IsAClone + "]");
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -18,7 +18,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
private void ElementDropped(ReorderableList.ReorderableListEventStruct droppedStruct)
|
private void ElementDropped(ReorderableList.ReorderableListEventStruct droppedStruct)
|
||||||
{
|
{
|
||||||
DebugLabel.text = "";
|
DebugLabel.text = "";
|
||||||
DebugLabel.text += "Dropped Object: " + droppedStruct.DropedObject.name + "\n";
|
DebugLabel.text += "Dropped Object: " + droppedStruct.DroppedObject.name + "\n";
|
||||||
DebugLabel.text += "Is Clone ?: " + droppedStruct.IsAClone + "\n";
|
DebugLabel.text += "Is Clone ?: " + droppedStruct.IsAClone + "\n";
|
||||||
if (droppedStruct.IsAClone)
|
if (droppedStruct.IsAClone)
|
||||||
DebugLabel.text += "Source Object: " + droppedStruct.SourceObject.name + "\n";
|
DebugLabel.text += "Source Object: " + droppedStruct.SourceObject.name + "\n";
|
||||||
|
|
|
@ -41,6 +41,19 @@ namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
_draggingObject = _rect;
|
_draggingObject = _rect;
|
||||||
_fromIndex = _rect.GetSiblingIndex();
|
_fromIndex = _rect.GetSiblingIndex();
|
||||||
|
//Send OnElementRemoved Event
|
||||||
|
if (_reorderableList.OnElementRemoved != null)
|
||||||
|
{
|
||||||
|
Debug.Log("removed");
|
||||||
|
_reorderableList.OnElementRemoved.Invoke(new ReorderableList.ReorderableListEventStruct
|
||||||
|
{
|
||||||
|
DroppedObject = _draggingObject.gameObject,
|
||||||
|
IsAClone = _reorderableList.CloneDraggedObject,
|
||||||
|
SourceObject = _reorderableList.CloneDraggedObject ? gameObject : _draggingObject.gameObject,
|
||||||
|
FromList = _reorderableList,
|
||||||
|
FromIndex = _fromIndex,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//Else Duplicate
|
//Else Duplicate
|
||||||
else
|
else
|
||||||
|
@ -62,6 +75,19 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
RefreshSizes();
|
RefreshSizes();
|
||||||
|
|
||||||
|
//Send OnElementGrabbed Event
|
||||||
|
if (_reorderableList.OnElementGrabbed != null)
|
||||||
|
{
|
||||||
|
Debug.Log("Grabbed");
|
||||||
|
_reorderableList.OnElementGrabbed.Invoke(new ReorderableList.ReorderableListEventStruct
|
||||||
|
{
|
||||||
|
DroppedObject = _draggingObject.gameObject,
|
||||||
|
IsAClone = _reorderableList.CloneDraggedObject,
|
||||||
|
SourceObject = _reorderableList.CloneDraggedObject ? gameObject : _draggingObject.gameObject,
|
||||||
|
FromList = _reorderableList,
|
||||||
|
FromIndex = _fromIndex,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
_isDragging = true;
|
_isDragging = true;
|
||||||
}
|
}
|
||||||
|
@ -78,7 +104,6 @@ namespace UnityEngine.UI.Extensions
|
||||||
//Set dragging object on cursor
|
//Set dragging object on cursor
|
||||||
_draggingObject.position = eventData.position;
|
_draggingObject.position = eventData.position;
|
||||||
|
|
||||||
|
|
||||||
//Check everything under the cursor to find a ReorderableList
|
//Check everything under the cursor to find a ReorderableList
|
||||||
EventSystem.current.RaycastAll(eventData, _raycastResults);
|
EventSystem.current.RaycastAll(eventData, _raycastResults);
|
||||||
for (int i = 0; i < _raycastResults.Count; i++)
|
for (int i = 0; i < _raycastResults.Count; i++)
|
||||||
|
@ -151,9 +176,12 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
|
|
||||||
//Send OnelementDropped Event
|
//Send OnelementDropped Event
|
||||||
|
if (_reorderableList.OnElementDropped != null)
|
||||||
|
{
|
||||||
|
Debug.Log("Dropped");
|
||||||
_reorderableList.OnElementDropped.Invoke(new ReorderableList.ReorderableListEventStruct
|
_reorderableList.OnElementDropped.Invoke(new ReorderableList.ReorderableListEventStruct
|
||||||
{
|
{
|
||||||
DropedObject = _draggingObject.gameObject,
|
DroppedObject = _draggingObject.gameObject,
|
||||||
IsAClone = _reorderableList.CloneDraggedObject,
|
IsAClone = _reorderableList.CloneDraggedObject,
|
||||||
SourceObject = _reorderableList.CloneDraggedObject ? gameObject : _draggingObject.gameObject,
|
SourceObject = _reorderableList.CloneDraggedObject ? gameObject : _draggingObject.gameObject,
|
||||||
FromList = _reorderableList,
|
FromList = _reorderableList,
|
||||||
|
@ -162,6 +190,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
ToIndex = _fakeElement.GetSiblingIndex() - 1
|
ToIndex = _fakeElement.GetSiblingIndex() - 1
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//We don't have an ReorderableList
|
//We don't have an ReorderableList
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue