Staggering buttons with GUI.SelectionGrid

I’m trying to offset buttons so they are layed out at a diagonal from each other. Each one corresponds to a different view of the screen; so, it would make sense to use GUI.SelectionGrid to have the buttons provide feedback for which screen the user is currently on. Is there anyway to do this with one SelectionGrid? I was thinking placing them in a GUILayout would be the way to go. If that’s the right path would it just take nesting the SelectionGrid between GUILayout.BeginHorizontal and BeginVertical?

Here’s a screen shot of what I’m attempting to accomplish:

18962-buttonlayout.jpg

The SelectionGrid just seems like the class I want to use to have selected buttons highlighted.

buttonlayout.jpg was blank when I tried to view it.

Let me post it back up.

1 Answer

1

There is no way to align the items within a selection grid afaik. I used toggle buttons with a button skin for that and controlled their state by an array.

just a small example:

bool[] myStates = new bool[3]{true, false, false};

...

GUILayout.BeginHorizontal(); //your custom layout instead
{
    if(GUILayout.Toggle(myStates[0], "Pay", myButtonStyle))
    {
        CheckState(myStates, 0);
    }
    if(GUILayout.Toggle(myStates[1], "Politics", myButtonStyle))
    {
        CheckState(myStates, 1);
    }
    if(GUILayout.Toggle(myStates[2], "Strike", myButtonStyle))
    {
        CheckState(myStates, 2);
    }
}
GUILayout.EndHorizontal();

...

protected void CheckState(bool[] values, int selectedIndex)
{
    for (int i = 0; i < values.Length; i++) 
    {
        values *= i == selectedIndex;*

}
}

oh yeah, and I could just skin the toggles to look more like a button.

Additionally an example for the skin config: [18964-screen+shot+2013-12-06+at+10.08.59.png|18964]

I have just one question about your code. I noticed commenting out values _= i == selectedIndex; stops the selected toggle from switching. How is values* changing the value of myStates without passing by reference?*_

NVM arrays are reference types.