Search Unity

Creating a 2D Bool Array for the Inspector

Discussion in 'Scripting' started by renman3000, Dec 18, 2014.

  1. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Is there some way I can make a gird of bools for the inspector?

    So, say 10 across and 10 down of bool[,] would show in the inspector as.....
    000000000000
    000000000000
    000000000000
    000000000000

    for example and I could go in and manipulate each value?
     
    JokerZappie likes this.
  2. Coldcalifornian

    Coldcalifornian

    Joined:
    Feb 11, 2014
    Posts:
    14
    You could create a custom Editor script with a series of EditorGUI.Toggle calls using the Toggle(Rect position, bool value); signature. You would have to create the Rects for each of the booleans...and it would be an ugly script.
     
  3. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Ok, so would you go against it?

    Currently, this issue for me is this...
    I have a gird, of tiles. Each tile I can set to be on or off. Right now I have a mapScript, which has 10 1D array's for each row. I set each of these arrays to be 10 in size, so now, by virtue I have my grid.

    The issue is, in order to adjust any value, I must open that array find that member and adjust. If I want to adjust another member in another row, I must find that row, array, open it, find its member and adjust.

    It would be a huge time saver to have a visual grid as opposed to what I am using.
     
  4. Coldcalifornian

    Coldcalifornian

    Joined:
    Feb 11, 2014
    Posts:
    14
    If you are not familiar with Editor Scripting, it will take you quite a while to get what you're describing to work. Your current technique may be a little annoying, but it does work. Unless you are going to repeat this process a couple hundred times, you will end up spending far more time creating the custom editor script.
     
  5. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    The thing is this is how I build levels.

    Hmm...
     
  6. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Hi there,
    So I was looking at the Physics Matrix, see pic. How is the made?
     
  7. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    I've just implemented this in a simple way. I used a multiline text box and then parse the string. 0 = off, 1 = on, \n = next row in the grid
     
    Tymianek likes this.