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 MichaelTaylor3d · May 06, 2013 at 06:09 PM · guiguilayout

GUILayout formatting help

Using a series of nested BeginVertical and BeginHorizontal GUILayouts, Ive created a nice flexible content section in my app that changes size depending on what is drawn inside each section.

My GUILayout consists of two vertical layouts side by side but the left vertical is divided into two verticals.

Ive attached a picture to show what I mean, alt text

What Id like to do as shown in the picture is make it so that when the right vertical section is small enough, the bottom vertical layout should expand all the way over.

Are there any ideas on configurations that could achieve this?

Thanks,

Here is my code for the layout

 public delegate void Content();
     
     public static void ThreeDownOneSide(Content[] panel1, Content[] panel2, Content[] panel3)
     {
         GUILayout.BeginHorizontal();        
         GUILayout.BeginVertical();
         
         GUILayout.BeginVertical();
         {
             foreach(Content content in panel1)
             {
                 if(!content.isNull())
                 {
                     content();
                 }
             }
         }
         GUILayout.EndVertical();
         
         GUILayout.BeginVertical();
         {
             foreach(Content content in panel2)
             {
                 if(!content.isNull())
                 {
                     content();
                 }
             }
         }
         GUILayout.EndVertical();
         
         GUILayout.EndVertical();            
         GUILayout.BeginVertical();
         {
             foreach(Content content in panel3)
             {
                 if(!content.isNull())
                 {
                     content();
                 }
             }
         }
         GUILayout.EndVertical();    
         GUILayout.EndHorizontal();
     }
flexible spaces.png (8.3 kB)
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 iwaldrop · May 07, 2013 at 06:17 AM

There really isn't a way to just 'expand all the way over'; you have to chose one or the other, but of course you know that.

So what you need is a conditional statement to choose which layout to use. I usually like to breakup my layouts into functions that I can use interchangeably. You can run the below script and switch between the two (very simple) examples by un/checking the layout flag in the inspector.

 using UnityEngine;
 using System.Collections;
 
 public class InterchangableGUI : MonoBehaviour
 {
     public bool layout;
     
     private delegate void DrawLayout();
     private DrawLayout layoutOne;
     private DrawLayout layoutTwo;
     
     void Awake()
     {
         layoutOne = new DrawLayout(LayoutOne);
         layoutTwo = new DrawLayout(LayoutTwo);
     }
     
     void OnGUI()
     {
         DrawLayout draw = layout ? layoutOne : layoutTwo;
         draw();
     }
     
     void LayoutOne()
     {
         GUILayout.Label("LayoutOne");
     }
     
     void LayoutTwo()
     {
         GUILayout.Label("LayoutTwo");
     }
 }
 
Comment
Add comment · Show 2 · 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 iwaldrop · May 07, 2013 at 06:22 AM 0
Share

A slight modification if you have more than one layout in $$anonymous$$d; the nice thing about delegates is you can assign methods from other scripts to be drawn in the same GUI function even though I've included them all in the same class for the sake of brevity.

 using UnityEngine;
 using System.Collections;
 
 public class InterchangableGUI : $$anonymous$$onoBehaviour
 {
     public int layout;
     
     private delegate void DrawLayout();
     private DrawLayout[] layouts = new DrawLayout[3];
     
     void Awake()
     {
         layouts[0] = new DrawLayout(LayoutOne);
         layouts[1] = new DrawLayout(LayoutTwo);
         layouts[2] = new DrawLayout(LayoutThree);
     }
     
     void OnGUI()
     {
         DrawLayout draw = layouts[layout];
         draw();
     }
     
     void LayoutOne()
     {
         GUILayout.Label("LayoutOne");
     }
     
     void LayoutTwo()
     {
         GUILayout.Label("LayoutTwo");
     }
     
     void LayoutThree()
     {
         GUILayout.Label("LayoutThree");
     }
 }
 
avatar image MichaelTaylor3d · May 07, 2013 at 01:10 PM 0
Share

Dang, thats what I was afraid of, having switch between different layouts manually. Well I suppose I can create a modified factory to do it automatically. However, the only way I can think of automatic switching is to be able to detect the size of each region and to switch between layouts depending on certain conditions. I have yet figured out how to detect the size of a GUILayout. Do you have any ideas?

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

13 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

Related Questions

Smoothly "add another GUI box"? 0 Answers

GUI.Window error. InvalidOperationException: Hashtable.Enumerator: snapshot out of sync. 0 Answers

know GUILayout current screen position 2 Answers

"'UnityEngine.GUI.DoTextField' is inaccessible due to its protection level." 1 Answer

Why can't I get my tooltip to show only when there is a tooltip set? 2 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