2015-10-30 00:07:17 +08:00
|
|
|
|
/// Credit Ziboo
|
|
|
|
|
/// Sourced from - http://forum.unity3d.com/threads/free-reorderable-list.364600/
|
|
|
|
|
|
|
|
|
|
using System;
|
2015-10-29 07:07:35 +08:00
|
|
|
|
using UnityEngine.Events;
|
|
|
|
|
|
2015-10-30 00:07:17 +08:00
|
|
|
|
namespace UnityEngine.UI.Extensions
|
2015-10-29 07:07:35 +08:00
|
|
|
|
{
|
2015-10-30 00:07:17 +08:00
|
|
|
|
[AddComponentMenu("UI/Extensions/Re-orderable list")]
|
|
|
|
|
public class ReorderableList : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public LayoutGroup ContentLayout;
|
2015-10-29 07:07:35 +08:00
|
|
|
|
|
2015-10-30 00:07:17 +08:00
|
|
|
|
public bool IsDraggable = true;
|
|
|
|
|
public RectTransform DraggableArea;
|
|
|
|
|
public bool CloneDraggedObject = false;
|
2015-10-29 21:12:26 +08:00
|
|
|
|
|
2015-10-30 00:07:17 +08:00
|
|
|
|
public bool IsDropable = true;
|
2015-10-29 21:12:26 +08:00
|
|
|
|
|
2015-10-29 07:07:35 +08:00
|
|
|
|
|
2015-10-30 00:07:17 +08:00
|
|
|
|
public ReorderableListHandler OnElementDropped = new ReorderableListHandler();
|
2015-10-29 07:07:35 +08:00
|
|
|
|
|
2015-10-30 00:07:17 +08:00
|
|
|
|
private RectTransform _content;
|
|
|
|
|
private ReorderableListContent _listContent;
|
|
|
|
|
|
|
|
|
|
public RectTransform Content
|
2015-10-29 21:12:26 +08:00
|
|
|
|
{
|
2015-10-30 00:07:17 +08:00
|
|
|
|
get
|
2015-10-29 21:12:26 +08:00
|
|
|
|
{
|
2015-10-30 00:07:17 +08:00
|
|
|
|
if (_content == null)
|
|
|
|
|
{
|
|
|
|
|
_content = ContentLayout.GetComponent<RectTransform>();
|
|
|
|
|
}
|
|
|
|
|
return _content;
|
2015-10-29 21:12:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-30 00:07:17 +08:00
|
|
|
|
private void Awake()
|
2015-10-29 07:07:35 +08:00
|
|
|
|
{
|
2015-10-30 00:07:17 +08:00
|
|
|
|
if (ContentLayout == null)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("You need to have a LayoutGroup content set for the list", gameObject);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (DraggableArea == null)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("You need to set a draggable area for the list", gameObject);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_listContent = ContentLayout.gameObject.AddComponent<ReorderableListContent>();
|
|
|
|
|
_listContent.Init(this);
|
2015-10-29 07:07:35 +08:00
|
|
|
|
}
|
2015-10-30 00:07:17 +08:00
|
|
|
|
|
|
|
|
|
#region Nested type: ReorderableListEventStruct
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
public struct ReorderableListEventStruct
|
2015-10-29 07:07:35 +08:00
|
|
|
|
{
|
2015-10-30 00:07:17 +08:00
|
|
|
|
public GameObject DropedObject;
|
|
|
|
|
public int FromIndex;
|
|
|
|
|
public ReorderableList FromList;
|
|
|
|
|
public bool IsAClone;
|
|
|
|
|
public GameObject SourceObject;
|
|
|
|
|
public int ToIndex;
|
|
|
|
|
public ReorderableList ToList;
|
2015-10-29 07:07:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-30 00:07:17 +08:00
|
|
|
|
#endregion
|
2015-10-29 07:07:35 +08:00
|
|
|
|
|
2015-10-30 00:07:17 +08:00
|
|
|
|
#region Nested type: ReorderableListHandler
|
2015-10-29 21:12:26 +08:00
|
|
|
|
|
2015-10-30 00:07:17 +08:00
|
|
|
|
[Serializable]
|
|
|
|
|
public class ReorderableListHandler : UnityEvent<ReorderableListEventStruct>
|
|
|
|
|
{
|
|
|
|
|
}
|
2015-10-29 21:12:26 +08:00
|
|
|
|
|
2015-10-30 00:07:17 +08:00
|
|
|
|
#endregion
|
2015-10-29 07:07:35 +08:00
|
|
|
|
}
|
|
|
|
|
}
|