Classic array look with dragging behavior is here!

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:

7012216--829597--locations.png

Enjoy!

7012216–829594–EditorMovableArrayAttribute.cs (149 Bytes)
7012216–833248–EditorMovableArray.cs (10 KB)
7012216–833251–EditorMovableArrayDrawer.cs (1.69 KB)

Did you know you can right-click on the EditorMobableArray and export a complete package of your three scripts as a .unitypackage file, then attach them here? You just have to untick dependencies on the bottom of the screen.

Yes, I’m aware of it. I decided to upload separate files to emphasize that it’s super small and could be fully customized to someone’s needs unlike current Unity’s implementation.

Maybe someone wants to get rid of selection rect or change its color. You could do it as the complete source is available for you to investigate and edit. Or maybe there is a bug and you want to fix it. You could do it too in no time!

Cheers!

I have found a way to get rid of excessive GUI.changed sets! Now it is only set to true when move has actually happened. It also eliminates unwanted additions to undo stack. Files in the first post are updated.

The unitypackage format is more like a zip file than anything – importing one will result in the complete source files appearing in your project in the original folder structure. Unity packages do not restrict one from freely investigating or editing the source code once imported.

To make it easier to view the source and contribute without having to download/import it, I would suggest creating a BitBucket/GitHub/GitLab repository to hold your source files, which will enable you to more easily publish updates and accept modifications from others in the form of pull requests.

As a bonus, you can also publish this package to openUPM which will make it possible to install your package to their project from the command line for anyone using it.