Hello,
I’m trying to make a reorderable array/list but I have never made an editor tool before so I’m kind of lost. Can someone help me to finish the script that I started?
Here’s the array I’m trying to make reorderable.
[SerializeField] private LegendElement[] LegendElements = null;
[Serializable]
private struct LegendElement
{
public Sprite Icon;
public Color IconColor;
public string IconText;
public Color IconTextColor;
public string IconName;
}
Here’s the editor script that I’ve written so far.
using UnityEngine;
using UnityEditor;
using UnityEditorInternal;
[CustomEditor(typeof(Legend))]
public class LegendEditor : Editor
{
private SerializedProperty Legend = null;
private ReorderableList List = null;
private void OnEnable()
{
Legend = serializedObject.FindProperty("LegendElement");
List = new ReorderableList(serializedObject, Legend, true, true, true, true);
List.drawElementCallback = DrawListItems;
List.drawHeaderCallback = DrawHeader;
}
private void DrawListItems(Rect rect, int index, bool isActive, bool isFocused)
{
SerializedProperty element = List.serializedProperty.GetArrayElementAtIndex(index);
// How to show the element in here?
}
private void DrawHeader(Rect rect)
{
EditorGUI.LabelField(rect, "Legend");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
List.DoLayoutList();
serializedObject.ApplyModifiedProperties();
}
}
So far, I’m getting this error in the editor, and the editor doesn’t show anything in the inspector.
