I've been working on a ReorderableList, but it's given me quite the headache. I've come to the point where I want to define a "drawElementCallback" -callback, which looks like this:
list.drawElementCallback = (rect, index, active, focused) => {
EditorGUI.PropertyField(rect, list.serializedProperty.GetArrayElementAtIndex(index), GUIContent.none);
};
What it's supposed to draw is one Vector3 object from an array of Vector3 objects. I get this property like this: ("property" is a SerializedProperty that contains the property that I need)
SerializedProperty locationsProperty = property.FindPropertyRelative("locations");
The array is declared as follows:
public Vector3[] locations;
Inside a container class that is marked as "Serializable".
The problem I kept getting with different code is that the ReorderableList shows all the Vectors correctly but it doesn't allow me to reorder any of the items, nor delete them (I can add new Vector3 objects and change them as expected).
With this code, I wanted to fix that issue. However, now I keep getting the following error:
"InvalidOperationException: The operation is not possible when moved past all properties (Next returned false)"
I wanted to make a reorderable list because it seemed easy, but I can't figure out the problem and I honestly wish I hadn't started working on it. It's taken up most of the past 3 days.
If anyone knows how to fix this, I would be very grateful.
To clarify, this code shows the array properly:
list.drawElementCallback = (rect, index, active, focused) => {
SerializedProperty item = locationsProperty.GetArrayElementAtIndex(index);
EditorGUI.BeginChangeCheck();
item.vector3Value = EditorGUI.Vector3Field(rect, string.Empty, item.vector3Value);
};
But doesn't allow me to remove or reorder items. I thought I should show the code to demonstrate that there are indeed array items.