Hi,
Since some time Unity has built-in reorderable list for arrays. I don’t quite like it, because it breaks the classic inspector look we had for arrays. Also, nested arrays look ugly to me. So, I decided to cleanup the mess and made a small drawer that brings back the classic look for arrays, but still allows them to be draggable. I used the same visual feedback for drag that is used in Hierarchy view (the blue line). For me it fits the Editor style much better.
I think it could also be used in older versions to enable dragging behavior for arrays as I’m not using anything fancy to draw the array.
Enough words, compare these two. My version is on the right:
It works as an attribute that you put on a serializable array. Note that you also have to put NonReorderable attribute to disable the default drawer if you’re using a recent version of Unity. Tested in Unity 2020.3.2f1.
using System;
using UnityEngine;
public class ArrayWithDefaultItemDrawer : MonoBehaviour
{
[Serializable]
public class NestedItem
{
public string Name;
}
[Serializable]
public class Item
{
public string Name;
public int Value;
public Vector3 Position;
[NonReorderable] // disable default drawer
[EditorMovableArray] // enable dragging with classic look!
public NestedItem[] NestedItems;
}
[NonReorderable] // disable default drawer
[EditorMovableArray] // enable dragging with classic look!
public Item[] Items;
}
Download 3 scripts below and put them according to this screenshot:
Enjoy!
7012216–829594–EditorMovableArrayAttribute.cs (149 Bytes)
7012216–833248–EditorMovableArray.cs (10 KB)
7012216–833251–EditorMovableArrayDrawer.cs (1.69 KB)