From 9b9aac4a74fac514f5374ea0383136a7ae32764e Mon Sep 17 00:00:00 2001 From: "Simon (darkside) Jackson" Date: Fri, 2 Oct 2020 18:17:47 +0100 Subject: [PATCH] Resolves #346 When cloned, reorderable list was creating a second List Content component that was not initialised. Refactored to wnsure only one list content was present and is initialised correctly --- .../Controls/ReorderableList/ReorderableList.cs | 10 ++++++++-- .../Controls/ReorderableList/ReorderableListContent.cs | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Runtime/Scripts/Controls/ReorderableList/ReorderableList.cs b/Runtime/Scripts/Controls/ReorderableList/ReorderableList.cs index c010421..c5c0cf2 100644 --- a/Runtime/Scripts/Controls/ReorderableList/ReorderableList.cs +++ b/Runtime/Scripts/Controls/ReorderableList/ReorderableList.cs @@ -89,8 +89,14 @@ namespace UnityEngine.UI.Extensions /// public void Refresh() { - Destroy(_listContent); - _listContent = ContentLayout.gameObject.AddComponent(); + + _listContent = ContentLayout.gameObject.GetComponent(); + + if (!_listContent) + { + _listContent = ContentLayout.gameObject.AddComponent(); + } + _listContent.Init(this); } diff --git a/Runtime/Scripts/Controls/ReorderableList/ReorderableListContent.cs b/Runtime/Scripts/Controls/ReorderableList/ReorderableListContent.cs index 9ef2e7a..8908aed 100644 --- a/Runtime/Scripts/Controls/ReorderableList/ReorderableListContent.cs +++ b/Runtime/Scripts/Controls/ReorderableList/ReorderableListContent.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; namespace UnityEngine.UI.Extensions { + [DisallowMultipleComponent] public class ReorderableListContent : MonoBehaviour { private List _cachedChildren; @@ -13,6 +14,7 @@ namespace UnityEngine.UI.Extensions private ReorderableListElement _ele; private ReorderableList _extList; private RectTransform _rect; + private bool _started = false; private void OnEnable() { @@ -27,12 +29,15 @@ namespace UnityEngine.UI.Extensions public void Init(ReorderableList extList) { + if (_started) { StopCoroutine(RefreshChildren()); } + _extList = extList; _rect = GetComponent(); _cachedChildren = new List(); _cachedListElement = new List(); StartCoroutine(RefreshChildren()); + _started = true; } private IEnumerator RefreshChildren()