• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by zerophase · Dec 06, 2013 at 07:19 AM · c#guiguilayoutselectiongrid

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:

alt text

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

buttonlayout.jpg (11.1 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Dec 06, 2013 at 07:20 AM 0
Share

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

avatar image zerophase · Dec 06, 2013 at 08:28 AM 0
Share

Let me post it back up.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by robhuhn · Dec 06, 2013 at 08:51 AM

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] = i == selectedIndex;
     }
 }
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zerophase · Dec 06, 2013 at 08:59 AM 0
Share

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

avatar image robhuhn · Dec 06, 2013 at 09:11 AM 0
Share

Additionally an example for the skin config:

alt text

screen shot 2013-12-06 at 10.08.59.png (32.1 kB)
avatar image zerophase · Dec 06, 2013 at 10:15 PM 0
Share

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

avatar image zerophase · Dec 07, 2013 at 08:37 AM 0
Share

NV$$anonymous$$ arrays are reference types.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

SelectionGrid is not returning a value!! 1 Answer

Styling an individual button in SelectionGrid 0 Answers

Multiple Cars not working 1 Answer

GUILayout not working for me C# 1 Answer

Is it possible to make EditorGuiLayout.ObjectField(Texture2D) look like ObjectField(String,Texture2D)? 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges