public static ReorderableList GetList(SerializedProperty property, ReorderableAttribute attrib, int id, string arrayPropertyName) { if (property == null) { return(null); } ReorderableList list = null; SerializedProperty array = property.FindPropertyRelative(arrayPropertyName); if (array != null && array.isArray) { if (!lists.TryGetValue(id, out list)) { if (attrib != null) { Texture icon = !string.IsNullOrEmpty(attrib.elementIconPath) ? AssetDatabase.GetCachedIcon(attrib.elementIconPath) : null; ReorderableList.ElementDisplayType displayType = attrib.singleLine ? ReorderableList.ElementDisplayType.SingleLine : ReorderableList.ElementDisplayType.Auto; list = new ReorderableList(array, attrib.add, attrib.remove, attrib.draggable, displayType, attrib.elementNameProperty, attrib.elementNameOverride, icon); list.paginate = attrib.paginate; list.pageSize = attrib.pageSize; list.sortable = attrib.sortable; list.elementLabels = attrib.labels; //handle surrogate if any if (attrib.surrogateType != null) { SurrogateCallback callback = new SurrogateCallback(attrib.surrogateProperty); list.surrogate = new ReorderableList.Surrogate(attrib.surrogateType, callback.SetReference); } } else { list = new ReorderableList(array, true, true, true); } lists.Add(id, list); } else { list.List = array; } } return(list); }
public static ReorderableCollection GetDrawableCollection(SerializedProperty property, ReorderableAttribute attrib = null, int id = -1, string backingListName = DefaultBackingListName) { // if (property == null) { return(null); } if (id == -1) { id = GetListId(property); } if (attrib == null) { attrib = new ReorderableAttribute(); } ReorderableCollection collection = null; var backingList = property.FindPropertyRelative(backingListName); var obj = GetTargetObjectOfProperty(property); if (backingList == null || !backingList.isArray || !(obj is BaseReorderableCollection)) { return(null); } if (!Lists.TryGetValue(id, out collection)) { var icon = !string.IsNullOrEmpty(attrib.elementIconPath) ? AssetDatabase.GetCachedIcon(attrib.elementIconPath) : null; var displayType = attrib.singleLine ? ReorderableCollection.ElementDisplayType.SingleLine : ReorderableCollection.ElementDisplayType.Auto; collection = new ReorderableCollection(backingList, attrib.add, attrib.remove, attrib.draggable, displayType, attrib.elementNameProperty, attrib.elementNameOverride, icon) { Paginate = attrib.paginate, PageSize = attrib.pageSize, sortable = attrib.sortable }; // handle surrogate if any if (attrib.surrogateType != null) { var callback = new SurrogateCallback(attrib.surrogateProperty); collection.surrogate = new ReorderableCollection.Surrogate(attrib.surrogateType, callback.SetReference); } Lists.Add(id, collection); } else { collection.List = backingList; } return(collection); }