Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
1
Question by Ereptor · Jul 15, 2013 at 04:51 PM · c#guiguilayoutresize

Dynamic GUI Columns in GUI Area? (C#)

I'm having a big issue with my GUI. The basic style I'm using is:

 GUILayout.BeginArea();
 GUILayout.FlexibleSpace();
 if(GUILayout.Button){}
 if(GUILayout.Button){}
 if(GUILayout.Button){}
 if(GUILayout.Button){}
 GUILayout.FlexibleSpace();
 GUILayout.EndArea();

Each time a button is clicked, it is eliminated from the menu. In the end, only one button will remain. It works perfectly if the buttons are listed vertically in one column, but I want the buttons to be larger and in two columns.

My buttons have a pre-set width and height. My GUI Area has a width of 800, my buttons each have a width of 300. How can I make them take up the full space of the GUI Area?

TL;DR: A GUILayout area has buttons that disappear. How can these buttons be divided into columns?

Comment
Add comment
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

1 Reply

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

Answer by perchik · Jul 15, 2013 at 04:56 PM

You'll want to look at GUILayout.BeginHorizontal() and GUILayout.BeginVertical()

Begin Vertical creates rows, beginHorizontal creates columns.

Your final script will probably look like this :

 GUILayout.BeginArea();
 GUILayout.BeginHorizontal(); //side by side columns
 
 GUILayout.BeginVertical(); //Layout objects vertically in each column
 ... button 1 ...
 ... button 2 ...
 GUILayout.EndVertical();
 
 GUILayout.BeginVertical();
 ... button 3 ...
 ... button 4 ...
 GUILayout.EndVertical();
 
 
 GUILayout.EndHorizontal();
 GUILayout.EndArea();


This will create a layout like this:

| button1 | button3 |

| button2 | button4 |

Comment
Add comment · Show 7 · 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 Ereptor · Jul 15, 2013 at 05:09 PM 0
Share

This works well enough for me. With another FlexibleSpace on either side of my rows, I can create two-button columns. It seems a little awkward to have a hopscotch effect (2 buttons, 1 button, 2 buttons) after one is eli$$anonymous$$ated, but it's the best outcome I could hope for at the moment.

Thank you for your help!

avatar image perchik · Jul 15, 2013 at 05:12 PM 1
Share

When you remove the button you could replace it with a GUILayout.Space and maintain the sizes of everything.

So that

 | 1 | 3 | 
 
 | 2 | 4 |  
 
 would become
 
 |   | 3 |
 
 | 2 | 4 | 

when you click on 1. (If I understand your problem correctly)

avatar image Ereptor · Jul 15, 2013 at 08:18 PM 0
Share

Oh! Great!

avatar image MrSKYone · Mar 07, 2014 at 03:01 PM 0
Share

Is it possible to do so when you have a generic function that create button according to and integer?

for(i, i < list.lenght, i++){ GUI.Button(Rect....) }

I would like them to be ordered into columns

avatar image Ereptor · Mar 07, 2014 at 04:58 PM 0
Share

This might be an amateur suggestion, but perhaps each row could be dependent on the integer exceeding a certain value?

For instance, if you want three columns:

If the number is more than 1, begin a horizontal space. Button 1 = List value 1. Button 2 = List value 2. Button 3 = List value 3.

If the number is more than 3, begin a horizontal space. Button 1 = List value 4. Button 2 = List value 5. Button 3 = List value 6.

Though if you wanted to use the GUILayout.Space, I suppose you'd have to check at every value... Right?

Show more comments

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.

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

GUILayout not working for me C# 1 Answer

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

Help with GUILayout and tooltip(C#) 1 Answer

Drawing several BeginArea inside a BeginScrollview (GUILayout) produces an unexpected behaviour 1 Answer

How can I enable/disable a script or a method in a script from another editorwindow script ? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges