【Unity3d编辑器从入门到精通】ReorderableList 可排序列表

ReorderableList是可以通过手动拖拽更改列表顺序,例子如下:


【Unity3d编辑器从入门到精通】ReorderableList 可排序列表_第1张图片
image.png
using UnityEditorInternal;
using UnityEditor;
using System.Collections.Generic;

public class ReorderableListTest : EditorWindow {

    private ReorderableList _list;
    //应该用持久化数据,案例暂时用这个
    private List _data = new List();

    public ReorderableListTest()
    {
        _list = new ReorderableList(_data, _data.GetType());
        _list.drawElementCallback = (rect, index, isActive, isFocused) =>
        {
            EditorGUI.TextField(rect,_data[index]);
        };

        _list.onAddCallback = (list) => 
        {
            _data.Add("");
        };
    }

    private void OnGUI()
    {
        _list.DoLayoutList();
        //_list.DoList(rect);根据rect调整位置
    }
}

你可能感兴趣的:(【Unity3d编辑器从入门到精通】ReorderableList 可排序列表)