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()