美文网首页
【Unity3d编辑器从入门到精通】ReorderableLis

【Unity3d编辑器从入门到精通】ReorderableLis

作者: 仰望星海 | 来源:发表于2017-08-29 15:54 被阅读1010次

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


image.png
using UnityEditorInternal;
using UnityEditor;
using System.Collections.Generic;

public class ReorderableListTest : EditorWindow {

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

    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编辑器从入门到精通】ReorderableLis

      本文链接:https://www.haomeiwen.com/subject/dwpodxtx.html