public static ReorderableList SetElementHeight(this ReorderableList _list, ReorderableList.ElementHeightCallbackDelegate _getHeight) { _list.elementHeightCallback = _getHeight; return(_list); }
private void InitList(ReorderableList.ElementCallbackDelegate drawCallback, ReorderableList.ElementHeightCallbackDelegate heightCallback) { List = new ReorderableList(_property.serializedObject, _property); List.drawHeaderCallback += rect => _property.isExpanded = EditorGUI.ToggleLeft(rect, _property.displayName, _property.isExpanded, EditorStyles.boldLabel); List.onCanRemoveCallback += (list) => { return(List.count > 0); }; List.drawElementCallback += drawCallback; List.elementHeightCallback += heightCallback; }
/// <summary> /// Create a <c>UnityEditorInternal.ReorderableList</c> with common settings. /// </summary> /// /// <remarks> /// I.e., the property label as the header, click to fold or expand the list, basic add and remove buttons. /// </remarks> /// /// <returns>The reorderable list.</returns> /// <param name="property">Property.</param> /// <param name="drawElementCallback">Draw element callback.</param> /// <param name="elementHeightCallback">Element height callback.</param> /* * The reference of reorderable list: * http://va.lent.in/unity-make-your-lists-functional-with-reorderablelist/ * * Set draggable again since it becomes false if the property is not editable. */ public static ReorderableList Create( SerializedProperty property, ReorderableList.ElementCallbackDelegate drawElementCallback = null, ReorderableList.ElementHeightCallbackDelegate elementHeightCallback = null ) { if (null == property) { throw new ArgumentNullException("property"); } var _result = new ReorderableList(property.serializedObject, property, true, true, true, true); _result.draggable = true; _result.drawElementCallback = drawElementCallback; _result.elementHeightCallback = elementHeightCallback; Wrap(_result); return(_result); }
public static CachedReorderableList GetListDrawer(SerializedProperty property, ReorderableList.HeaderCallbackDelegate drawHeaderCallback, ReorderableList.ElementHeightCallbackDelegate getElementHeightCallback, ReorderableList.ElementCallbackDelegate drawElementCallback, ReorderableList.FooterCallbackDelegate drawFooterCallback = null, ReorderableList.AddCallbackDelegate onAddCallback = null, ReorderableList.RemoveCallbackDelegate onRemoveCallback = null, ReorderableList.SelectCallbackDelegate onSelectCallback = null, ReorderableList.ChangedCallbackDelegate onChangedCallback = null, ReorderableList.ReorderCallbackDelegate onReorderCallback = null, ReorderableList.CanRemoveCallbackDelegate onCanRemoveCallback = null, ReorderableList.AddDropdownCallbackDelegate onAddDropdownCallback = null) { if (property == null) { throw new System.ArgumentNullException("property"); } if (!property.isArray) { throw new System.ArgumentException("SerializedProperty must be a property for an Array or List", "property"); } int hash = GetPropertyHash(property); CachedReorderableList lst; if (_lstCache.TryGetValue(hash, out lst)) { lst.ReInit(property.serializedObject, property); } else { lst = new CachedReorderableList(property.serializedObject, property); _lstCache[hash] = lst; } lst.drawHeaderCallback = drawHeaderCallback; lst.elementHeightCallback = getElementHeightCallback; lst.drawElementCallback = drawElementCallback; lst.drawFooterCallback = drawFooterCallback; lst.onAddCallback = onAddCallback; lst.onRemoveCallback = onRemoveCallback; lst.onSelectCallback = onSelectCallback; lst.onChangedCallback = onChangedCallback; lst.onReorderCallback = onReorderCallback; lst.onCanRemoveCallback = onCanRemoveCallback; lst.onAddDropdownCallback = onAddDropdownCallback; return(lst); }
public ListControl MakeCustomHeight(ReorderableList.ElementHeightCallbackDelegate callback) { _getElementHeight = callback; return(this); }
public ReorderableListProperty(SerializedProperty prop, bool indentElems = false, ReorderableList.ElementCallbackDelegate drawCallback = null, ReorderableList.ElementHeightCallbackDelegate heightCallback = null) { _property = prop; indentElements = indentElems; if (drawCallback == null) { drawCallback = DrawElement; } if (heightCallback == null) { heightCallback = (idx) => { return(Mathf.Max(EditorGUIUtility.singleLineHeight, EditorGUI.GetPropertyHeight(_property.GetArrayElementAtIndex(idx), GUIContent.none, true)) + 4.0f); }; } InitList(drawCallback, heightCallback); }