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
{
[RequireComponent(typeof(RectTransform)), DisallowMultipleComponent]
[AddComponentMenu("UI/Extensions/Re-orderable list")]
public class ReorderableList : MonoBehaviour
{
[Tooltip("Child container with re-orderable items in a layout group")]
public LayoutGroup ContentLayout;
public bool IsDraggable = true;
[Tooltip("Parent area to draw the dragged element on top of containers. Defaults to the root Canvas")]
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;
[Tooltip("Can new draggable items be dropped in to the container?")]
public bool IsDropable = true;
[Header("UI Re-orderable Events")]
public ReorderableListHandler OnElementDropped = new ReorderableListHandler();
public ReorderableListHandler OnElementGrabbed = new ReorderableListHandler();
public ReorderableListHandler OnElementRemoved = new ReorderableListHandler();
private RectTransform _content;
private ReorderableListContent _listContent;
@ -37,14 +46,19 @@ namespace UnityEngine.UI.Extensions
private void Awake()
{
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;
}
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;
}
_listContent = ContentLayout.gameObject.AddComponent<ReorderableListContent>();
@ -56,7 +70,7 @@ namespace UnityEngine.UI.Extensions
[Serializable]
public struct ReorderableListEventStruct
{
public GameObject DropedObject;
public GameObject DroppedObject;
public int FromIndex;
public ReorderableList FromList;
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
}
}

View File

@ -18,7 +18,7 @@ namespace UnityEngine.UI.Extensions
private void ElementDropped(ReorderableList.ReorderableListEventStruct droppedStruct)
{
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";
if (droppedStruct.IsAClone)
DebugLabel.text += "Source Object: " + droppedStruct.SourceObject.name + "\n";

View File

@ -41,6 +41,19 @@ namespace UnityEngine.UI.Extensions
{
_draggingObject = _rect;
_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
@ -62,6 +75,19 @@ namespace UnityEngine.UI.Extensions
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;
}
@ -78,7 +104,6 @@ namespace UnityEngine.UI.Extensions
//Set dragging object on cursor
_draggingObject.position = eventData.position;
//Check everything under the cursor to find a ReorderableList
EventSystem.current.RaycastAll(eventData, _raycastResults);
for (int i = 0; i < _raycastResults.Count; i++)
@ -151,16 +176,20 @@ namespace UnityEngine.UI.Extensions
//Send OnelementDropped Event
_reorderableList.OnElementDropped.Invoke(new ReorderableList.ReorderableListEventStruct
if (_reorderableList.OnElementDropped != null)
{
DropedObject = _draggingObject.gameObject,
IsAClone = _reorderableList.CloneDraggedObject,
SourceObject = _reorderableList.CloneDraggedObject ? gameObject : _draggingObject.gameObject,
FromList = _reorderableList,
FromIndex = _fromIndex,
ToList = _currentReorderableListRaycasted,
ToIndex = _fakeElement.GetSiblingIndex() - 1
});
Debug.Log("Dropped");
_reorderableList.OnElementDropped.Invoke(new ReorderableList.ReorderableListEventStruct
{
DroppedObject = _draggingObject.gameObject,
IsAClone = _reorderableList.CloneDraggedObject,
SourceObject = _reorderableList.CloneDraggedObject ? gameObject : _draggingObject.gameObject,
FromList = _reorderableList,
FromIndex = _fromIndex,
ToList = _currentReorderableListRaycasted,
ToIndex = _fakeElement.GetSiblingIndex() - 1
});
}
}
//We don't have an ReorderableList
else