From 953770528df195faed31602d70e471da5f24a7ae Mon Sep 17 00:00:00 2001 From: Ziboo Date: Thu, 29 Oct 2015 14:12:26 +0100 Subject: [PATCH] Reorderable List: - Added support for HorizontalLayout and GridLayout - Change Property RectTransform Content to LayoutGroup ContentLayout --HG-- branch : develop_5.2 --- Scripts/ReorderableList/ReorderableList.cs | 34 ++++++++-- .../ReorderableList/ReorderableList.cs.meta | 24 +++---- Scripts/ReorderableList/ReorderableList.unity | Bin 59384 -> 90216 bytes .../ReorderableList.unity.meta | 16 ++--- .../ReorderableListContent.cs.meta | 24 +++---- .../ReorderableList/ReorderableListDebug.cs | 4 +- .../ReorderableListDebug.cs.meta | 24 +++---- .../ReorderableList/ReorderableListElement.cs | 62 ++++++++++++++++-- .../ReorderableListElement.cs.meta | 24 +++---- 9 files changed, 142 insertions(+), 70 deletions(-) diff --git a/Scripts/ReorderableList/ReorderableList.cs b/Scripts/ReorderableList/ReorderableList.cs index 75d0c7e..7261c1c 100644 --- a/Scripts/ReorderableList/ReorderableList.cs +++ b/Scripts/ReorderableList/ReorderableList.cs @@ -1,27 +1,41 @@ using System; using UnityEngine; using UnityEngine.Events; +using UnityEngine.UI; public class ReorderableList : MonoBehaviour { - public RectTransform Content; + public LayoutGroup ContentLayout; public bool IsDraggable = true; public RectTransform DraggableArea; public bool CloneDraggedObject = false; public bool IsDropable = true; - - + + public ReorderableListHandler OnElementDropped = new ReorderableListHandler(); + private RectTransform _content; private ReorderableListContent _listContent; + public RectTransform Content + { + get + { + if (_content == null) + { + _content = ContentLayout.GetComponent(); + } + return _content; + } + } + private void Awake() { - if (Content == null) + if (ContentLayout == null) { - Debug.LogError("You need to set the content for the list", gameObject); + Debug.LogError("You need to have a LayoutGroup content set for the list", gameObject); return; } if (DraggableArea == null) @@ -29,10 +43,12 @@ public class ReorderableList : MonoBehaviour Debug.LogError("You need to set a draggable area for the list", gameObject); return; } - _listContent = Content.gameObject.AddComponent(); + _listContent = ContentLayout.gameObject.AddComponent(); _listContent.Init(this); } + #region Nested type: ReorderableListEventStruct + [Serializable] public struct ReorderableListEventStruct { @@ -45,8 +61,14 @@ public class ReorderableList : MonoBehaviour public ReorderableList ToList; } + #endregion + + #region Nested type: ReorderableListHandler + [Serializable] public class ReorderableListHandler : UnityEvent { } + + #endregion } \ No newline at end of file diff --git a/Scripts/ReorderableList/ReorderableList.cs.meta b/Scripts/ReorderableList/ReorderableList.cs.meta index 031c85d..0c82a31 100644 --- a/Scripts/ReorderableList/ReorderableList.cs.meta +++ b/Scripts/ReorderableList/ReorderableList.cs.meta @@ -1,12 +1,12 @@ -fileFormatVersion: 2 -guid: 6b333d67eb08d464d823874f6a1666c2 -timeCreated: 1446072130 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: +fileFormatVersion: 2 +guid: 6b333d67eb08d464d823874f6a1666c2 +timeCreated: 1446072130 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/ReorderableList/ReorderableList.unity b/Scripts/ReorderableList/ReorderableList.unity index a684dec14d4cb123eaf6754a6eb83c5940addf03..2be9c022e800913ae3fa0b6b649b3e8b02998c8e 100644 GIT binary patch delta 15438 zcmbuF4}4X{mB;73JRo4iC99TGz#L2paSJj2nh!K^P;E? z5JJcx#y?;X#V9CG9&S^sHB>9X(rxP2ZmLMbNIN)|f7#!ed(O*!Gk!kX{cQB| zX68G0&Y3g+&b{Xz|9#rw)*i!^YC5O_(K$+~Q&eaZp+`9X@VTHvJ zNJ%8drA-d%spre&tN}2KzdclPA z^fkF-iz`aYD<&)|UwC`DT5#)B%8jd+=X`%ShR3S zMS1Dmg%v5835zOG@^#|Wv3K+ie3JjVx8k#wArYAo(IL$UQNX%3&uOlV2hEE|(kIoANYu2xXt? zHJ45A`886#1Nzg;CIwFm=u6I+dHxw_oJ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s4%VyVf^@BRFN(w!7aKA@Q`xc?s7JShCAJX|a8vp _raycastResults = new List(); private ReorderableList _currentReorderableListRaycasted; private RectTransform _draggingObject; - private ReorderableList _reorderableList; + private LayoutElement _draggingObjectLE; + private Vector2 _draggingObjectOriginalSize; private RectTransform _fakeElement; + private LayoutElement _fakeElementLE; private int _fromIndex; private bool _isDragging; private RectTransform _rect; + private ReorderableList _reorderableList; + #region IBeginDragHandler Members public void OnBeginDrag(PointerEventData eventData) { @@ -39,21 +43,29 @@ public class ReorderableListElement : MonoBehaviour, IDragHandler, IBeginDragHan { GameObject clone = Instantiate(gameObject); _draggingObject = clone.GetComponent(); - _draggingObject.sizeDelta = gameObject.GetComponent().sizeDelta; } //Put _dragging object into the draggin area + _draggingObjectOriginalSize = gameObject.GetComponent().rect.size; + _draggingObjectLE = _draggingObject.GetComponent(); _draggingObject.SetParent(_reorderableList.DraggableArea, false); _draggingObject.SetAsLastSibling(); //Create a fake element for previewing placement _fakeElement = new GameObject("Fake").AddComponent(); - _fakeElement.gameObject.AddComponent().preferredHeight = _rect.rect.height; + _fakeElementLE = _fakeElement.gameObject.AddComponent(); + + + RefreshSizes(); _isDragging = true; } + #endregion + + #region IDragHandler Members + public void OnDrag(PointerEventData eventData) { if (!_isDragging) @@ -77,7 +89,9 @@ public class ReorderableListElement : MonoBehaviour, IDragHandler, IBeginDragHan //If nothing found or the list is not dropable, put the fake element outsite if (_currentReorderableListRaycasted == null || _currentReorderableListRaycasted.IsDropable == false) { + RefreshSizes(); _fakeElement.transform.SetParent(_reorderableList.DraggableArea, false); + } //Else find the best position on the list and put fake element on the right index else @@ -87,10 +101,17 @@ public class ReorderableListElement : MonoBehaviour, IDragHandler, IBeginDragHan float minDistance = float.PositiveInfinity; int targetIndex = 0; + float dist = 0; for (int j = 0; j < _currentReorderableListRaycasted.Content.childCount; j++) { var c = _currentReorderableListRaycasted.Content.GetChild(j).GetComponent(); - float dist = Mathf.Abs(c.position.y - eventData.position.y); + + if (_currentReorderableListRaycasted.ContentLayout is VerticalLayoutGroup) + dist = Mathf.Abs(c.position.y - eventData.position.y); + else if (_currentReorderableListRaycasted.ContentLayout is HorizontalLayoutGroup) + dist = Mathf.Abs(c.position.x - eventData.position.x); + else if (_currentReorderableListRaycasted.ContentLayout is GridLayoutGroup) + dist = (Mathf.Abs(c.position.x - eventData.position.x) + Mathf.Abs(c.position.y - eventData.position.y)); if (dist < minDistance) { @@ -99,11 +120,17 @@ public class ReorderableListElement : MonoBehaviour, IDragHandler, IBeginDragHan } } + RefreshSizes(); _fakeElement.SetSiblingIndex(targetIndex); _fakeElement.gameObject.SetActive(true); + } } + #endregion + + #region IEndDragHandler Members + public void OnEndDrag(PointerEventData eventData) { _isDragging = false; @@ -114,8 +141,10 @@ public class ReorderableListElement : MonoBehaviour, IDragHandler, IBeginDragHan //Put the dragged object into the content and at the right index if (_currentReorderableListRaycasted != null && _currentReorderableListRaycasted.IsDropable) { + RefreshSizes(); _draggingObject.SetParent(_currentReorderableListRaycasted.Content, false); _draggingObject.SetSiblingIndex(_fakeElement.GetSiblingIndex()); + //Send OnelementDropped Event _reorderableList.OnElementDropped.Invoke(new ReorderableList.ReorderableListEventStruct @@ -129,7 +158,7 @@ public class ReorderableListElement : MonoBehaviour, IDragHandler, IBeginDragHan ToIndex = _fakeElement.GetSiblingIndex() - 1 }); } - //We don't have an ReorderableList + //We don't have an ReorderableList else { //If it's a clone, delete it @@ -137,9 +166,10 @@ public class ReorderableListElement : MonoBehaviour, IDragHandler, IBeginDragHan { Destroy(_draggingObject.gameObject); } - //Else replace the draggedObject to his first place + //Else replace the draggedObject to his first place else { + RefreshSizes(); _draggingObject.SetParent(_reorderableList.Content, false); _draggingObject.SetSiblingIndex(_fromIndex); } @@ -151,6 +181,26 @@ public class ReorderableListElement : MonoBehaviour, IDragHandler, IBeginDragHan Destroy(_fakeElement.gameObject); } + #endregion + + private void RefreshSizes() + { + Vector2 size = _draggingObjectOriginalSize; + + if (_currentReorderableListRaycasted != null && _currentReorderableListRaycasted.IsDropable) + { + var firstChild = _currentReorderableListRaycasted.Content.GetChild(0); + if (firstChild != null) + { + size = firstChild.GetComponent().rect.size; + } + } + + _draggingObject.sizeDelta = size; + _fakeElementLE.preferredHeight = _draggingObjectLE.preferredHeight = size.y; + _fakeElementLE.preferredWidth = _draggingObjectLE.preferredWidth = size.x; + } + public void Init(ReorderableList reorderableList) { _reorderableList = reorderableList; diff --git a/Scripts/ReorderableList/ReorderableListElement.cs.meta b/Scripts/ReorderableList/ReorderableListElement.cs.meta index 58605e8..cd587fb 100644 --- a/Scripts/ReorderableList/ReorderableListElement.cs.meta +++ b/Scripts/ReorderableList/ReorderableListElement.cs.meta @@ -1,12 +1,12 @@ -fileFormatVersion: 2 -guid: 916e98f1b982a9a4082fcc45c87b66c5 -timeCreated: 1446072130 -licenseType: Pro -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: +fileFormatVersion: 2 +guid: 916e98f1b982a9a4082fcc45c87b66c5 +timeCreated: 1446072130 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: