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
3
Question by Johan 4 · Mar 01, 2011 at 04:46 PM · inspectormenu

Making a collapsible menu in the inspector

I noticed some scripts have different options in collapsible menus in the inspector. For example there's a collapsible menu named "Resolution" and when you open it, it shows the properties.

How do they do it?

In c# preferred, but I guess I could possibly convert from js. Thanks

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

4 Replies

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

Answer by Molix · Mar 01, 2011 at 05:26 PM

You can use the EditorGUILayout.Foldout control. It is basically just a special toggle control; assign it to a boolean, and if it is true then draw the controls "inside", if it is false then don't.

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 Johan 4 · Mar 01, 2011 at 05:45 PM 0
Share

That requires using unityeditor, I don't want that. I've seen this being done without unityeditor

avatar image Molix · Mar 01, 2011 at 06:06 PM 0
Share

Your question does say "in the inspector". Anyway, there isn't really any magic to it; it is just a toggle that displays a little arrow icon pointing sideways or down. So if you want one at runtime, just use Toggle with a couple custom styles that contain arrows.

avatar image
7

Answer by znoey · Aug 13, 2012 at 04:45 PM

I'm sure this question is incredibly old but i stumbled upon it while looking for something else.

Based on the comments you need to make a serializable class to contain the data you want to be foldable. So in my FakeDataBehaviour as a monobehaviour, we have a FakeData class that contains something interesting. We define multiple ones inside my class. In the inspector, these will appear as foldable objects for setting the specific values.

for example:

 public class FakeDataBehaviour : MonoBehaviour

{ [System.Serializable] public class Data { string name; float someValue; }

[SerializeField] Data myData1; [SerializeField] Data myData2; // do more stuff... }

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
avatar image
3

Answer by EuanHollidge · Jun 30, 2017 at 01:57 PM

I know this is years ago but I think the answer you were looking for was to create a Struct with the vars inside then create a value for it. That gives the fold up menu with the GUI stuff.

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
avatar image
1

Answer by normand · Oct 01, 2018 at 02:19 AM

 private int p_workingMode = 0;
 
  public  override  void OnInspectorGUI(){
 GUIContent[] operationsOptions = new GUIContent[ 3];   //////Number of button in the ToolBar
            operationsOptions[ 0 ] = new GUIContent( "Your Menu Text1",  your Icon1 );
            operationsOptions[ 1 ] = new GUIContent(  "Your Menu Text2",  your Icon2 );
             operationsOptions[2 ] = new GUIContent(  "Your Menu Text3",  your Icon3 );
             p_workingMode = GUILayout.Toolbar( p_workingMode, operationsOptions );
          EditorGUILayout.Separator();
             
             switch (p_workingMode) {
      
                 case 0:
                 TerrainTool();
                 break;
                
                 case 1:
                 TextureTool();
                 break;
                 
                 case 2:
                 VegetationTool();
                 break;
                 }
 }
 
 void TerrainTool(){
 ////your stuff too show
  EditorGUILayout.PropertyField( your variable);
             if (GUILayout.Button( "Your name of the button" )) {
               your void();
                 }
 }


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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to create a drop down menu in editor inspector 5 Answers

Inspector scripting, adding lists, checkboxes and buttons [With Image] 0 Answers

How can I make a small context menu in the inspector? 3 Answers

NullRefenceException Using Arrays 2 Answers

Changing position in inspector changes rotation 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