Click or drag to resize
Serialized property inside editor window

The serialized property version of this field can also be used in editor windows. This allows you to take advantage of the automatic undo and redo capabilities which Unity provides.

In this example a reorderable list field is shown when an object containing the following behaviour is selected:

using System.Collections.Generic;
using UnityEngine;

public class SomeBehaviour : MonoBehaviour {
    public List<string> wishlist = new List<string>();
}

Before we can interact with the wishlist property we must create an instance of SerializedObject. This is done each time the user selection changes.

using Rotorz.ReorderableList;
using UnityEditor;
using UnityEngine;

public class ArrayPropertyWindow : EditorWindow {

    private SerializedObject _serializedObject;
    private SerializedProperty _wishlistProperty;

    void OnEnable() {
        // Consider selection when window is first shown.
        OnSelectionChange();
    }

    void OnSelectionChange() {
        // Get editable `SomeBehaviour` objects from selection.
        var filtered = Selection.GetFiltered(typeof(SomeBehaviour), SelectionMode.Editable);
        if (filtered.Length == 0) {
            _serializedObject = null;
            _wishlistProperty = null;
        }
        else {
            // Let's work with the first filtered result.
            _serializedObject = new SerializedObject(filtered[0]);
            _wishlistProperty = _serializedObject.FindProperty("wishlist");
        }

        Repaint();
    }

    void OnGUI() {
        if (_serializedObject == null)
            return;
        _serializedObject.Update();

        ReorderableListGUI.ListField(_wishlistProperty);

        _serializedObject.ApplyModifiedProperties();
    }

}