3
\$\begingroup\$

Let's say I have the following code:

public List<Armor> armors = new List<Armor> {
    new Armor() { name = "Black set",         folder = "black_set"},
    new Armor() { name = "Conquistador",      folder = "conquistador"},
    new Armor() { name = "Crusader",          folder = "crusader"},
    new Armor() { name = "Gothic Plate",      folder = "gothic_plate"},
    new Armor() { name = "K.D.",              folder = "kd"},
    new Armor() { name = "Lorica segmentata", folder = "lorica_segmentata"},
    new Armor() { name = "Rusty",             folder = "rusty"},
    new Armor() { name = "Spartan",           folder = "spartan"}
};

This appears in the editor like this:

enter image description here

While this is acceptable, there are a couple features I am missing: Lets take for instance the Sorting Layer list:

enter image description here

Here there are 2 features that I would like:

  1. The ability to reorder elements on the editor
  2. The ability to add more elements using + or -

Is there any way to add this functionality into my List?

\$\endgroup\$
2
  • \$\begingroup\$ You would have to write an editor script. It would be possible, but a lot of work. \$\endgroup\$ Jan 22, 2016 at 15:02
  • 2
    \$\begingroup\$ Wouldn't worry about the general amount of work needed for the functionality itself. Unity offers this. \$\endgroup\$
    – Athos vk
    Jan 22, 2016 at 15:20

2 Answers 2

1
\$\begingroup\$

You want to use Rotorz open-source Reorderable List to save yourself some time. This is the library I use to do exactly what you want. It makes Lists Reorderable in the inspector like the Sorting Layers and more without you having to write more custom inspector code then you need. Here's the library.

\$\endgroup\$
0
\$\begingroup\$

Being specific I would say

public ReorderableList(SerializedObject serializedObject, SerializedProperty elements, bool draggable, bool displayHeader, bool displayAddButton, bool displayRemoveButton);

Here is the tutorial to this. As it is always great to use which domain owners provide, so this Rotorz UI extensions are also good but I would recommend native library which Unity provides inside UnityEditorInternal dll

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .