diff --git a/Runtime/Scripts/Controls/ReorderableList/ReorderableList.cs b/Runtime/Scripts/Controls/ReorderableList/ReorderableList.cs index a710886..5ef840c 100644 --- a/Runtime/Scripts/Controls/ReorderableList/ReorderableList.cs +++ b/Runtime/Scripts/Controls/ReorderableList/ReorderableList.cs @@ -6,7 +6,6 @@ using UnityEngine.Events; namespace UnityEngine.UI.Extensions { - [RequireComponent(typeof(RectTransform)), DisallowMultipleComponent] [AddComponentMenu("UI/Extensions/Re-orderable list")] public class ReorderableList : MonoBehaviour @@ -31,11 +30,11 @@ namespace UnityEngine.UI.Extensions // This sets every item size (when being dragged over this list) to the current size of the first element of this list [Tooltip("Should items being dragged over this list have their sizes equalized?")] - public bool EqualizeSizesOnDrag = false; + public bool EqualizeSizesOnDrag = false; + [Tooltip("Maximum number of items this container can hold")] public int maxItems = int.MaxValue; - [Header("UI Re-orderable Events")] public ReorderableListHandler OnElementDropped = new ReorderableListHandler(); public ReorderableListHandler OnElementGrabbed = new ReorderableListHandler(); @@ -62,7 +61,7 @@ namespace UnityEngine.UI.Extensions } } - Canvas GetCanvas() + public Canvas GetCanvas() { Transform t = transform; Canvas canvas = null; @@ -73,8 +72,7 @@ namespace UnityEngine.UI.Extensions while (canvas == null && lvl < lvlLimit) { - canvas = t.gameObject.GetComponent(); - if (canvas == null) + if (!t.gameObject.TryGetComponent(out canvas)) { t = t.parent; } @@ -95,7 +93,6 @@ namespace UnityEngine.UI.Extensions private void Start() { - if (ContentLayout == null) { Debug.LogError("You need to have a child LayoutGroup content set for the list: " + name, gameObject); @@ -114,7 +111,6 @@ namespace UnityEngine.UI.Extensions Refresh(); } - #region Nested type: ReorderableListEventStruct [Serializable] @@ -136,13 +132,10 @@ namespace UnityEngine.UI.Extensions #endregion - #region Nested type: ReorderableListHandler [Serializable] - public class ReorderableListHandler : UnityEvent - { - } + public class ReorderableListHandler : UnityEvent { } public void TestReOrderableListTarget(ReorderableListEventStruct item) { @@ -152,4 +145,4 @@ namespace UnityEngine.UI.Extensions #endregion } -} +} \ No newline at end of file diff --git a/Runtime/Scripts/Controls/ReorderableList/ReorderableListContent.cs b/Runtime/Scripts/Controls/ReorderableList/ReorderableListContent.cs index 8908aed..ef5292a 100644 --- a/Runtime/Scripts/Controls/ReorderableList/ReorderableListContent.cs +++ b/Runtime/Scripts/Controls/ReorderableList/ReorderableListContent.cs @@ -21,7 +21,6 @@ namespace UnityEngine.UI.Extensions if(_rect)StartCoroutine(RefreshChildren()); } - public void OnTransformChildrenChanged() { if(this.isActiveAndEnabled)StartCoroutine(RefreshChildren()); diff --git a/Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs b/Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs index 8cba2f9..0a137ac 100644 --- a/Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs +++ b/Runtime/Scripts/Controls/ReorderableList/ReorderableListElement.cs @@ -8,7 +8,6 @@ using UnityEngine.EventSystems; namespace UnityEngine.UI.Extensions { - [RequireComponent(typeof(RectTransform), typeof(LayoutElement))] public class ReorderableListElement : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler { @@ -24,7 +23,7 @@ namespace UnityEngine.UI.Extensions [SerializeField] private bool isDroppableInSpace = false; - + [Tooltip("Can this element be dropped in another container?")] public bool IsTransferable { get { return _isTransferable; } @@ -61,7 +60,6 @@ namespace UnityEngine.UI.Extensions #region IBeginDragHandler Members - public void OnBeginDrag(PointerEventData eventData) { if (!_canvasGroup) { _canvasGroup = gameObject.GetOrAddComponent(); } @@ -142,12 +140,9 @@ namespace UnityEngine.UI.Extensions _isDragging = true; } - #endregion - #region IDragHandler Members - public void OnDrag(PointerEventData eventData) { if (!_isDragging) @@ -179,7 +174,6 @@ namespace UnityEngine.UI.Extensions //If nothing found or the list is not dropable, put the fake element outside if (_currentReorderableListRaycasted == null || _currentReorderableListRaycasted.IsDropable == false -// || (_oldReorderableListRaycasted != _reorderableList && !IsTransferable) || ((_fakeElement.parent == _currentReorderableListRaycasted.Content ? _currentReorderableListRaycasted.Content.childCount - 1 : _currentReorderableListRaycasted.Content.childCount) >= _currentReorderableListRaycasted.maxItems && !_currentReorderableListRaycasted.IsDisplacable) @@ -194,7 +188,7 @@ namespace UnityEngine.UI.Extensions } } //Else find the best position on the list and put fake element on the right index - else + else if (_currentReorderableListRaycasted == _reorderableList || IsTransferable) { if (_currentReorderableListRaycasted.Content.childCount < _currentReorderableListRaycasted.maxItems && _fakeElement.parent != _currentReorderableListRaycasted.Content) { @@ -245,12 +239,9 @@ namespace UnityEngine.UI.Extensions } } - #endregion - #region Displacement - private void displaceElement(int targetIndex, Transform displaced) { _displacedFromIndex = targetIndex; @@ -343,7 +334,6 @@ namespace UnityEngine.UI.Extensions } - public void finishDisplacingElement() { if (_displacedObject.parent == null) @@ -355,12 +345,9 @@ namespace UnityEngine.UI.Extensions _displacedObject = null; _displacedObjectLE = null; } - #endregion - #region IEndDragHandler Members - public void OnEndDrag(PointerEventData eventData) { _isDragging = false; @@ -473,11 +460,9 @@ namespace UnityEngine.UI.Extensions } _canvasGroup.blocksRaycasts = true; } - #endregion - - void CancelDrag() + private void CancelDrag() { _isDragging = false; //If it's a clone, delete it @@ -556,4 +541,4 @@ namespace UnityEngine.UI.Extensions _canvasGroup = gameObject.GetOrAddComponent(); } } -} +} \ No newline at end of file