Testing complete for Re-Orderable Lists

Added Editor Menus

--HG--
branch : develop_5.2
release
Simon (darkside) Jackson 2015-10-29 21:01:19 +00:00
parent a88c7a9c1b
commit 5bd1751993
4 changed files with 742 additions and 312 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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,16 +46,21 @@ 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>();
return;
} }
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;
}
_listContent = ContentLayout.gameObject.AddComponent<ReorderableListContent>(); _listContent = ContentLayout.gameObject.AddComponent<ReorderableListContent>();
_listContent.Init(this); _listContent.Init(this);
} }
@ -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
} }
} }

View File

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

View File

@ -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;
} }
@ -77,8 +103,7 @@ 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,16 +176,20 @@ namespace UnityEngine.UI.Extensions
//Send OnelementDropped Event //Send OnelementDropped Event
_reorderableList.OnElementDropped.Invoke(new ReorderableList.ReorderableListEventStruct if (_reorderableList.OnElementDropped != null)
{ {
DropedObject = _draggingObject.gameObject, Debug.Log("Dropped");
IsAClone = _reorderableList.CloneDraggedObject, _reorderableList.OnElementDropped.Invoke(new ReorderableList.ReorderableListEventStruct
SourceObject = _reorderableList.CloneDraggedObject ? gameObject : _draggingObject.gameObject, {
FromList = _reorderableList, DroppedObject = _draggingObject.gameObject,
FromIndex = _fromIndex, IsAClone = _reorderableList.CloneDraggedObject,
ToList = _currentReorderableListRaycasted, SourceObject = _reorderableList.CloneDraggedObject ? gameObject : _draggingObject.gameObject,
ToIndex = _fakeElement.GetSiblingIndex() - 1 FromList = _reorderableList,
}); FromIndex = _fromIndex,
ToList = _currentReorderableListRaycasted,
ToIndex = _fakeElement.GetSiblingIndex() - 1
});
}
} }
//We don't have an ReorderableList //We don't have an ReorderableList
else else