效果圖:
公司網絡限制,後面上傳
代碼:
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();
}
}