Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Octopoid · Jul 07, 2016 at 03:19 PM · guieditor-scriptingeditorguieditor extensionskin

Default toggle style

I'm writing a custom editor inspector, which uses a custom skin. Everything seems to work fine, but I've found something which doesn't act quite as I'd expect.

I've redefined the toggle style in my skin, however when using the following code, I see the default checkbox.

 toggle = EditorGUILayout.Toggle(toggle);

When I change it to the following, I see my custom toggle:

 toggle = EditorGUILayout.Toggle(toggle, GUI.skin.toggle);

I assume this means the default style for the toggle is not skin.toggle? Can I make this work without having to define I want the toggle style for the toggles?

(I've since noticed I seem to get the same problem with other controls, such as the textbox - buttons however seem to use the current skin by default as expected.)

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
Best Answer

Answer by Bunny83 · Jul 07, 2016 at 03:52 PM

A GUISkin only affects the runtime GUI controls (GUI / GUILayout). The editor controls (EditorGUI / EditorGUILayout) are just "extensions" of editor specific controls which do not use the GUI.skin.

The editor controls use the EditorStyles class which is hardcoded. The members are read only properties which are directly used in the method overloads which do not explicitly take a GUIStyle.

So you have to pass your GUIStyle manually.

Keep in mind that EditorGUI and EditorGUILayout are just extensions of the ordinary GUI and GUILayout controls. They are not a replacement. You can still use GUILayout.Toggle inside editor code.

"EditorGUILayout.Toggle" is just a special editor / inspector version of the toggle.

So the short answer is you have to pass your style manually. However you should be able to just do this:

 toggle = EditorGUILayout.Toggle(toggle, "toggle");

as long as you set your GUISkin to GUI.skin. Unity has an implicit casting operator from string to GUIStyle. So whenever a GUIStyle is expected it looks up the string in the current skin. Even this works:

 GUIStyle style = "button";

This way you can also look up custom style names defined in your skin.

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 Octopoid · Jul 07, 2016 at 04:04 PM 0
Share

Perfect, thanks - I'd forgotten you could just use the string names like that. That makes sense as to why Buttons are styled and stuff with editor versions is not too.

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

75 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 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 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 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 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 I get a reference to the default editor windows (Hierarchy, Console, and Inspector)? 1 Answer

How to tell if any textField has keyboard focus in editor? 2 Answers

Lining up GUI 1 Answer

Custom inspector difficulties creating a Box / Group like widget 1 Answer

Editor GUI Foldout header style customization 0 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