0

I am doing a custom editor (not property drawer) to change the display of a list in the inspector.

For example, I want every new element to show a popup selection field instead of property field. I also might want to add another field next to it later.

serializedList = serializedObject.FindProperty("list"); //list of int
for(int i = 0; i < serializedList.arraySize; i++)
{
    var value = serializedList.GetArrayElementAtIndex(i);
    index = EditorGUILayout.Popup(label, value.intValue, options.ToArray());
}

What I would like is to be able to add and remove values in the inspector (with the + and - buttons).

Basically I want the list to look like a default list in the inspector, but with my own element fields.

Is it possible to draw a default list, but only change the way elements are displayed?

I would prefer not to use property drawers for this, since I'm using the custom editor for other things also.

EDIT: I ended up using a property drawer to modify the rows, then just implementing a PropertyField in the custom editor containing the list.

mrxan
  • 51
  • 7
  • 1
    You should use a `ReorderableList` it is quite complex to setup but extremely powerful and fancy and complete customizable ;) [here](https://blog.terresquall.com/2020/03/creating-reorderable-lists-in-the-unity-inspector/) is a pretty good tutorial ... Doesn't look like the default list though .. but way better ^^ allows ordering elements by drag and drop etc .. [here](https://stackoverflow.com/questions/54516221/how-to-select-elements-in-nested-reorderablelist-in-a-customeditor) is an example implementation of my self – derHugo Apr 29 '21 at 19:51
  • [here](https://stackoverflow.com/questions/59781045/im-trying-to-use-reorderablelist-in-inspector-but-its-not-working-good-how-sh) is another one ;) and [here](https://stackoverflow.com/a/56186364/7111561) a quite complex one ^^ ... Hope these help as a start point – derHugo Apr 29 '21 at 19:55
  • For now I would actually tend to close this question as too broad/asking for a tool etc .. but I'd suggest you look at the links, play around with it and if you have a specific implementation issue then I would be happy too help ;) – derHugo Apr 29 '21 at 20:04
  • I was actually thinking of using an Reorderable list for this, but it seemed unnecessary, especially since I don't need the elements to be reorderable. – mrxan Apr 29 '21 at 20:32
  • In this case as far as I can tell from your code all that is missing is a) Wrap this in a `Foldout` and b) add a `Size` field .. or if you want add `+` and `-` buttons .. they will just increase or decrease the `arraySize` .. tricky might be to insert and remove items in the middle though – derHugo Apr 30 '21 at 04:04

1 Answers1

0

I ended up using a property drawer to modify the rows, then just implementing a PropertyField in the custom editor containing the list.

mrxan
  • 51
  • 7