unity編輯器工具—— 可排序列表

效果圖:

公司網絡限制,後面上傳

 

 

代碼:


using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
[CustomEditor(typeof(NewBehaviourScript))]
public class testEditor : Editor {
    /// <summary>
    /// 掛載在物體上的腳本
    /// </summary>
    private NewBehaviourScript nb;
    /// <summary>
    /// 腳本數據
    /// </summary>
    private List<GameObject> data = new List<GameObject>();

    private ReorderableList _list;

    private void OnEnable()
    {
        nb = target as NewBehaviourScript;
        data = nb.GetList;

        _list = new ReorderableList(data, typeof(GameObject), true, false, false, false);

        _list.drawElementCallback = (rect, index, isActive, isFocused) => {
            EditorGUI.ObjectField(rect, data[index].name, data[index], data[index].GetType(), true);
        };

        _list.drawHeaderCallback = rect => {
            GUI.Label(rect, "列表");
        };
    }

    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        _list.DoLayoutList();
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章