Unity Editor 编辑器拓展 06——ReorderableList 可拖动列表 的参数详解

namespace UnityEditorInternal
{
    public class ReorderableList
    {
        public bool showDefaultBackground; //是否显示默认背景
        public float footerHeight; //脚注高度
        public float headerHeight; //标题高度
        public float elementHeight;    //设置单个元素的高度
        public bool displayRemove; //显示移除按钮
        public bool displayAdd; //显示添加按钮

        #region 回调
        public HeaderCallbackDelegate drawHeaderCallback;//绘制表头回调
        public CanAddCallbackDelegate onCanAddCallback;
        public CanRemoveCallbackDelegate onCanRemoveCallback;
        public SelectCallbackDelegate onMouseUpCallback; //当鼠标抬起回调
        public DragCallbackDelegate onMouseDragCallback; //当鼠标拖动回调
        public ChangedCallbackDelegate onChangedCallback; 
        public AddDropdownCallbackDelegate onAddDropdownCallback;
        public RemoveCallbackDelegate onRemoveCallback;//点击删除按钮回调
        public ElementCallbackDelegate drawElementCallback;//绘制元素的回调
        public ElementCallbackDelegate drawElementBackgroundCallback;// 绘制元素的背景的回调
        public DrawNoneElementCallback drawNoneElementCallback;
        public ElementHeightCallbackDelegate elementHeightCallback;
        public FooterCallbackDelegate drawFooterCallback;
        public ReorderCallbackDelegate onReorderCallback;
        public SelectCallbackDelegate onSelectCallback;//选中元素的回调
        public AddCallbackDelegate onAddCallback;//点击添加按钮回调
        #endregion

        public ReorderCallbackDelegateWithDetails onReorderCallbackWithDetails;


        #region 构造函数
        public ReorderableList(IList elements, Type elementType);

        public ReorderableList(SerializedObject serializedObject, SerializedProperty elements);

        public ReorderableList(IList elements, Type elementType, bool draggable, bool displayHeader, bool displayAddButton, bool displayRemoveButton);

        public ReorderableList(SerializedObject serializedObject, SerializedProperty elements, bool draggable, bool displayHeader, bool displayAddButton, bool displayRemoveButton);

        #endregion 

        public static Defaults defaultBehaviours { get; } //超有用,默认的各种回调函数
        public SerializedProperty serializedProperty { get; set; }
        public int count { get; } //元素个数
        public bool draggable { get; set; } //是否可拖动
        public int index { get; set; }  //当前的索引
        public IList list { get; set; }

        public void DoLayoutList();   //显示该控件
        public void DoList(Rect rect);
        public float GetHeight();
        public void GrabKeyboardFocus();
        public bool HasKeyboardControl();
        public void ReleaseKeyboardFocus();

        //默认的方法和参数  在defaultBehaviours 中获取
        public class Defaults
        {
            public const int dragHandleWidth = 20;
            public const int padding = 6;
            public readonly GUIStyle elementBackground;
            public readonly GUIStyle draggingHandle;
            public readonly GUIStyle headerBackground;
            public readonly GUIStyle footerBackground;
            public readonly GUIStyle boxBackground;
            public readonly GUIStyle preButton;
            public GUIContent iconToolbarPlus;
            public GUIContent iconToolbarPlusMore;
            public GUIContent iconToolbarMinus;

            public Defaults();

            public void DoAddButton(ReorderableList list);
            public void DoRemoveButton(ReorderableList list);
            public void DrawElement(Rect rect, SerializedProperty element, object listItem, bool selected, bool focused, bool draggable);
            public void DrawElementBackground(Rect rect, int index, bool selected, bool focused, bool draggable);
            public void DrawElementDraggingHandle(Rect rect, int index, bool selected, bool focused, bool draggable);
            public void DrawFooter(Rect rect, ReorderableList list);
            public void DrawHeader(Rect headerRect, SerializedObject serializedObject, SerializedProperty element, IList elementList);
            public void DrawHeaderBackground(Rect headerRect);
            public void DrawNoneElement(Rect rect, bool draggable);
        }

        //定义的委托
        public delegate void FooterCallbackDelegate(Rect rect);
        public delegate void ElementCallbackDelegate(Rect rect, int index, bool isActive, bool isFocused);
        public delegate float ElementHeightCallbackDelegate(int index);
        public delegate void DrawNoneElementCallback(Rect rect);
        public delegate void DragCallbackDelegate(ReorderableList list);
        public delegate void ReorderCallbackDelegate(ReorderableList list);
        public delegate void SelectCallbackDelegate(ReorderableList list);
        public delegate void AddCallbackDelegate(ReorderableList list);
        public delegate void AddDropdownCallbackDelegate(Rect buttonRect, ReorderableList list);
        public delegate void RemoveCallbackDelegate(ReorderableList list);
        public delegate void ChangedCallbackDelegate(ReorderableList list);
        public delegate bool CanRemoveCallbackDelegate(ReorderableList list);
        public delegate bool CanAddCallbackDelegate(ReorderableList list);
        public delegate void HeaderCallbackDelegate(Rect rect);
        public delegate void ReorderCallbackDelegateWithDetails(ReorderableList list, int oldIndex, int newIndex);
    }
}

实际的使用参考

https://blog.csdn.net/qq_26999509/article/details/77782177

https://blog.csdn.net/qq_26999509/article/details/77801852

 

实际使用的注意

在绘制元素的回调中不能使用layout类型的控件。

不能使用Editor.CreateEditor()获得的窗口,调用OnInspector()

每一个元素的绘制不好自适应,只能为所有元素定制同一种显示样式。所以如果想进行多态化的显示的话,是无法在元素绘制回调中进行的。

当元素较少的话,可以设一个字段记录当前的index,然后在ReOrderableList控件的下面,使用Editor.CreateEditor()获得的窗口,调用OnInspector(),进行显示。

元素较多的话,请自己设计列表。定制功能。

 

并且,在删掉元素的时候,并不会调整列表,原先的index处 会变成null。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值