Search Unity

Grouping multiple arrays in inspector?

Discussion in 'Scripting' started by derkoi, Feb 6, 2016.

  1. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,260
    I have a spawn script which consists of 3 arrays, an array of gameobjects to spawn, an array of ints for the spawn amount and an array of bools for enable/disable of each object.

    Right now it's messy, I need to look down the list for the corresponding element number:



    So I'm wondering if I can group these together so it looks like this:



    Any help would be appreciated as I'm new to editor design.
     
  2. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906
    Create a class with these variables, make an array of this class. Decorate class with [System.Serializable]
     
    Radivarig and Lars12231 like this.
  3. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,260
    Wow, thanks that's working. Is there a way to change the 'Element 0' to the name of the prefab I'll be spawning?
     
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,334
    Yes. You'll need to make a custom property drawer for your serializeable class. The doc example shows exactly your case - an array that gets drawn in a readable way.

    EDIT:

    You could also consider building a reorderable list, which is what it says on the tin, but also allows you to specify exactly how you draw the elements. There's a good example here.

    Note that you can use EditorGUI.PropertyField to have a property drawn using it's property drawer - so you can create a reorderable list and have the elements in it drawn using your custom property drawers.
     
    miraycalskn likes this.
  5. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,260
    Thanks, I'll take a look at those links.
     
  6. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,741
    Yeah the reorderableList takes a little work to setup but lets you draw the data into the list pretty much anyway you want
     
  7. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    This is almost what you're looking for, but if the class has a field 'name', that will show up instead of the element number.
     
    Radivarig, derkoi and ThermalFusion like this.