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
0
Question by Patrik · Aug 08, 2010 at 05:39 PM · guilayoutbox

Encase GUILayout area

Hi, I need to do this: 1)create a nice box with a title on top 2)add an unknown number of buttons in this box I can't figure out how to do this because the box and the area require an explicit size, but I can't know this values a priori

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

2 Replies

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

Answer by Molix · Aug 08, 2010 at 07:12 PM

As you've probably noticed, the GUILayout functions don't take Rect's. However, an important one does: BeginArea.

So basically you define a rectangle with BeginArea, then layout your buttons inside without worrying about their coordinates. Depending on how many buttons and the size of your area, you may want to put the buttons in a scroll view. e.g.

public string[] buttonNames; private Vector2 scroller = new Vector2();

void OnGUI() { GUILayout.BeginArea( new Rect( 50, 50, 100, 200 ) ); scroller = GUILayout.BeginScrollview( scroller ); foreach( string buttonName in buttonNames ) { if( GUILayout.Button( buttonName ) ) { Debug.Log("You pressed " + buttonName ); } } GUILayout.EndScrollview(); GUILayout.EndArea(); }

Comment
Add comment · Show 3 · 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 Patrik · Aug 09, 2010 at 09:02 AM 0
Share

thank you but this is not what i really want. basically i need to make something like this image (http://unity3d.com/support/documentation/Images/manual/gui-Layout-0.jpg) but without an hardcoded size. no matter how many buttons i place, the box must always resize to surround them

avatar image Molix · Aug 09, 2010 at 01:43 PM 0
Share

I misunderstood the "box and the area require an explicit size" as being your requirement. In that case, just change the BeginArea/EndArea to BeginVertical with a style, e.g. BeginVertical( GUI.skin.GetStyle("Box") );

avatar image Patrik · Aug 10, 2010 at 05:28 PM 0
Share

Thank you, that did it

avatar image
1

Answer by Uzquiano · Mar 16, 2011 at 01:24 PM

Hei Patrik this answer comes a bit late though for the future some will read it, and it will help anyway.

So, this is my solution for your same problem:

    GUILayout.BeginArea(Rect(810,120,180,700));
// Starts a vertical group
GUILayout.BeginVertical ("box", GUILayout.ExpandHeight(false));

First create a Rect long enough that it will include as many elements as needed and then in the BeginVertical add the ExpandHeight control as it is shown in the previous code.

Cheers,

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

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

No one has followed this question yet.

Related Questions

GUILayout margin bug? 2 Answers

Text color change onHover 2 Answers

Drawing a GUI box by specifying the two corners 1 Answer

Strange behaviour GUI.Box 1 Answer

Box Trigger and Mesh Collider on one object. 1 Answer


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