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

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调整位置
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,973评论 19 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,466评论 25 708
  • 日子亦步亦趋 内心惶惶不安 屡次扪心自问 答案模棱两可...... 现实与理想总是相差甚远 欣赏与比较始终在较量 ...
    pinkzier阅读 98评论 0 1
  • 我仔细查看黑色背包,我认为该带的东西已经全部带上了,“没有问题了。” “那么走吧。”阿什微笑着挽住了我的胳膊。 面...
    九号咖啡屋阅读 1,840评论 1 23
  • 标签(空格分隔): 编程 Go官方文档 Using the tour 1.1 Hello, 世界 Welcome...
    uangianlap阅读 1,542评论 0 5