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
pull/413/head
Simon (darkside) Jackson 2020-10-02 18:17:47 +01:00
parent 69fd735e65
commit 9b9aac4a74
2 changed files with 13 additions and 2 deletions

View File

@ -89,8 +89,14 @@ namespace UnityEngine.UI.Extensions
/// </summary> /// </summary>
public void Refresh() public void Refresh()
{ {
Destroy(_listContent);
_listContent = ContentLayout.gameObject.GetComponent<ReorderableListContent>();
if (!_listContent)
{
_listContent = ContentLayout.gameObject.AddComponent<ReorderableListContent>(); _listContent = ContentLayout.gameObject.AddComponent<ReorderableListContent>();
}
_listContent.Init(this); _listContent.Init(this);
} }

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
namespace UnityEngine.UI.Extensions namespace UnityEngine.UI.Extensions
{ {
[DisallowMultipleComponent]
public class ReorderableListContent : MonoBehaviour public class ReorderableListContent : MonoBehaviour
{ {
private List<Transform> _cachedChildren; private List<Transform> _cachedChildren;
@ -13,6 +14,7 @@ namespace UnityEngine.UI.Extensions
private ReorderableListElement _ele; private ReorderableListElement _ele;
private ReorderableList _extList; private ReorderableList _extList;
private RectTransform _rect; private RectTransform _rect;
private bool _started = false;
private void OnEnable() private void OnEnable()
{ {
@ -27,12 +29,15 @@ namespace UnityEngine.UI.Extensions
public void Init(ReorderableList extList) public void Init(ReorderableList extList)
{ {
if (_started) { StopCoroutine(RefreshChildren()); }
_extList = extList; _extList = extList;
_rect = GetComponent<RectTransform>(); _rect = GetComponent<RectTransform>();
_cachedChildren = new List<Transform>(); _cachedChildren = new List<Transform>();
_cachedListElement = new List<ReorderableListElement>(); _cachedListElement = new List<ReorderableListElement>();
StartCoroutine(RefreshChildren()); StartCoroutine(RefreshChildren());
_started = true;
} }
private IEnumerator RefreshChildren() private IEnumerator RefreshChildren()