/// Credit Ziboo /// Sourced from - http://forum.unity3d.com/threads/free-reorderable-list.364600/ using System.Collections; using System.Collections.Generic; namespace UnityEngine.UI.Extensions { public class ReorderableListContent : MonoBehaviour { private List _cachedChildren; private List _cachedListElement; private ReorderableListElement _ele; private ReorderableList _extList; private RectTransform _rect; private void OnEnable() { if(_rect)StartCoroutine(RefreshChildren()); } public void OnTransformChildrenChanged() { if(this.isActiveAndEnabled)StartCoroutine(RefreshChildren()); } public void Init(ReorderableList extList) { _extList = extList; _rect = GetComponent(); _cachedChildren = new List(); _cachedListElement = new List(); StartCoroutine(RefreshChildren()); } private IEnumerator RefreshChildren() { //Handle new chilren for (int i = 0; i < _rect.childCount; i++) { if (_cachedChildren.Contains(_rect.GetChild(i))) continue; //Get or Create ReorderableListElement _ele = _rect.GetChild(i).gameObject.GetComponent() ?? _rect.GetChild(i).gameObject.AddComponent(); _ele.Init(_extList); _cachedChildren.Add(_rect.GetChild(i)); _cachedListElement.Add(_ele); } //HACK a little hack, if I don't wait one frame I don't have the right deleted children yield return 0; //Remove deleted child for (int i = _cachedChildren.Count - 1; i >= 0; i--) { if (_cachedChildren[i] == null) { _cachedChildren.RemoveAt(i); _cachedListElement.RemoveAt(i); } } } } }