Reorderable List Control for Unity
| Generic list inside editor window |
Items from generic lists can be presented using custom item drawers. A custom item drawer is essentially a delegate which is called to draw each list item. The generic list adaptor can be subclassed instead if items of varying heights are needed (see Custom list adaptor).
Tip |
|---|
|
Consider using serialized properties instead if undo/redo support is needed. |
using Rotorz.ReorderableList; using System.Collections.Generic; using UnityEditor; using UnityEngine; public class GenericListWindow : EditorWindow { private List<string> _nameList; void OnEnable() { _nameList = new List<string>(); } void OnGUI() { ReorderableListGUI.ListField(_nameList, DrawListItem); } string DrawListItem(Rect position, string value) { // Text fields do not like null values! if (value == null) value = ""; return EditorGUI.TextField(position, value); } }
#pragma strict
import Rotorz.ReorderableList;
import System.Collections.Generic;
class GenericListWindow extends EditorWindow {
var _nameList:List.<String>;
function OnEnable() {
_nameList = new List.<String>();
}
function OnGUI() {
ReorderableListGUI.ListField(_nameList, DrawListItem);
}
function DrawListItem(position:Rect, value:String):String {
// Text fields do not like null values!
if (value == null)
value = '';
return EditorGUI.TextField(position, value);
}
}
Tip