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 moreyes · Jul 30, 2013 at 05:50 AM · editoreditor-scripting

Creating a toolbar with toggleable buttons

I want to create a toolbar in the editor with buttons that remain active when clicked, to simulate "tabs" like these from the Lightmapping window:

alt text

Is it possible to make something like this look native, like in the example above? And if so, which control should I use, or any other directions?

Comment
Add comment · Show 2
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 robertbu · Jul 30, 2013 at 06:14 AM 0
Share

The link to your image is broken. Image too big?

avatar image moreyes · Jul 30, 2013 at 09:53 AM 0
Share

No, it is really small... and I can see it. $$anonymous$$ust be a problem in the system. :P It is here, anyway: http://imgur.com/LTic7zo

2 Replies

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

Answer by moreyes · Jul 30, 2013 at 03:07 PM

Sorry for answering my own question.

There're actually built-in controls for this, I found out later... they are called GUILayout.Toolbar or GUI.Toolbar, and look exactly like the one from the Lightmapping window. :D

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 Jamora · Jul 30, 2013 at 10:39 AM

You need to use an array of booleans to back up a row of normal buttons.

If the boolean for the corresponding button is set true, then that button should be marked active. There are several ways you can do this. One way is to create a GUISkin and two styles, then set the values there. Or if you need to have it in a custom editor, then you might have to make three custom styles, inactiveButton and activeButton and a normalButton. normalButton is just a temp variable to tell the buttons. InactiveButton has the normal textures for its state, and activeButton has them inversed, i.e. looks like it's being pressed when it's not. (the values you need to modify in the GUIStyles are normal and active. ). You'll want to probably make your own textures, the default ones aren't very impressive. You can change it by accessing the background field in the styles.

Because what I just wrote is pretty incoherent, here's something I hacked together to give you an idea:

     GUIStyle inActiveButton;
     GUIStyle activeButton;
     GUIStyle buttonStyle;
     bool[] boolArray = {false,false};
     void OnGUI(){
         inActiveButton = new GUIStyle(GUI.skin.button);
         activeButton = new GUIStyle(GUI.skin.button);
         buttonStyle = new GUIStyle(GUI.skin.button);        
         GUI.skin.button.margin = new RectOffset(0,0,0,0);
         GUILayout.BeginHorizontal();
         for(int i=0;i<2;i++){
             if(boolArray[i] == true){
                 activeButton.normal = GUI.skin.button.active;
                 buttonStyle = activeButton;
             }
             else
                 buttonStyle = inActiveButton;
             
             if(GUILayout.Button(i.ToString (),buttonStyle)){
                 boolArray[i] = !boolArray[i];
             }
         }
         GUILayout.EndHorizontal();
     }
Comment
Add comment · Show 1 · 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 moreyes · Jul 30, 2013 at 11:41 AM 0
Share

Custom button styles then, eh? Let me play with these ideas, and try to replicate EditorStyles.$$anonymous$$iButtonLeft and so on to group the buttons. The hard part will be to make it look native with normal and pro skins.

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

16 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

Related Questions

How do you force a particle system to play all the time in the editor, not just when it is selected? 5 Answers

Set MinWidth for EditorWindow 1 Answer

EditorWindow texture effected by Playmode Color Tint 1 Answer

Start/Stop Playmode from editor script 10 Answers

Draw specific Object Inspector into Rect 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