• 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 Itinerant · Jan 04, 2013 at 06:21 PM · nested

Nested Selection Grid?

I want to make a GUI list that I can expand and contract, like this: Nested List.

I can't think of how to go about it, though. I have an array for the first level, and arrays for the sub-columns, and arrays for a sub-sub-column, but I can't figure out how to accept a random number of each and expand and contract. Any suggestions?

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
0

Answer by Loius · Jan 04, 2013 at 06:44 PM

The Editor GUI has a Foldout control; you'd have to replicate it in-game with a clickable icon+label.

Expandable GUI is easiest to accomplish with GUILayout:

 [pseudocode]
 
 GUILayout.BeginVertical();
 foreach button {
   button.open = GUIUtils.Foldout(button.name);
   if ( button.open ) {
     GUIUtils.BeginIndent(); // see below snippet
     // display contents of the button
     GUIUtils.EndIndent();
   }
 } 
 GUILayout.EndVertical();

I actually wrote a fully-clickable foldout control because I hate clicking the triangle:

(This is from my GUIUtils.cs file, comment out the (FontStyle)1 bit if you don't want bold text)

     /* These functions begin and end a horizontal indentation */
     public static void BeginIndent(string style) { GUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.BeginVertical(style); }
     public static void BeginIndent() { BeginIndent(""); }
     public static void EndIndent() { GUILayout.EndVertical(); GUILayout.EndHorizontal(); }

 /////////////////////////////////////////////////////////////////////////////
     /*
     * This section makes an EditorGUILayout.Foldout, except you can actually click anywhere on the word to open it
     * instead of having to click on the teeny-tiny triangle.
     * 
     * ... what the bananas, Unity
     */ 
     private static GUIStyle openFoldoutStyle;
     private static GUIStyle closedFoldoutStyle;
     private static bool initted;
     
     private static void Init() {
         openFoldoutStyle = new GUIStyle( GUI.skin.FindStyle("Foldout") );
         openFoldoutStyle.fontStyle = (FontStyle)1;
         openFoldoutStyle.stretchHeight = true;
         closedFoldoutStyle = new GUIStyle( openFoldoutStyle );
         openFoldoutStyle.normal = openFoldoutStyle.onNormal;
         openFoldoutStyle.active = openFoldoutStyle.onActive;
         initted = true;
     }
     
     public static bool Foldout(bool open, string text ) { return Foldout(open, new GUIContent(text)); }
     public static bool Foldout(bool open, GUIContent text ) {
         if ( !initted ) Init();
         
         if ( open ) { 
             if ( GUILayout.Button( text, openFoldoutStyle, GUILayout.Height(20) ) ) {
                 GUI.FocusControl ("");
                 GUI.changed = false; // force change-checking group to take notice
                 GUI.changed = true;
                 return false;
             }
         } else {
             if ( GUILayout.Button( text, closedFoldoutStyle, GUILayout.Height(20) ) ) { 
                 GUI.FocusControl ("");
                 GUI.changed = false; // force change-checking to take notice
                 GUI.changed = true;
                 return true;
             }
         }
         return open;
     }


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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

Editor utility for handling nested prefabs.. 4 Answers

Nested for-loop freezing Unity 1 Answer

How to display my castle name at runtime 3 Answers

Is it ok to use nested classes, to cache and access components? 1 Answer

C#: Worlking with nested Dictionaries 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