效果图:
公司网络限制,后面上传
代码:
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();
}
}