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
2
Question by alexanderameye · Mar 03, 2017 at 08:52 PM · editorguiiconguistyleinternal

Custom Icons for EditorGUIUtility.IconContent

I can use the built-in icons in Unity for example like this:

 iconToolbarRemoveAll = EditorGUIUtility.IconContent("d_winbtn_mac_close");

which gives me the red close button from OSX. But how can I use my own icons, for example an Icon that I have placed in my assets folder?

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

Answer by Bunny83 · Mar 03, 2017 at 10:06 PM

"EditorGUIUtility.IconContent" just returns a cached GUIContent. A GUIContent is just a data class that groups three things together:

  • A text (string)

  • An image (Texture)

  • A tooltip (string)

If you want to create a GUIContent object with your own image, just create one:

 GUIContent icon = new GUIContent(yourTexture);

The constructor of GUIContent has several overloads which allows to use any combination of text image and tooltip. The only thing that isn't possible to create only a tooltip, but that doesn't make any sense^^.

You can also change the image, the text or the tooltip after you created the object. You shouldn't mess around with the built-in GUIContent as they are cached and might be used by other parts of the editor. If you want to modify a built-in GUIContent to use it in your code, create a copy:

 yourContent = new GUIContent(builtinContent);
 yourContent.image = yourImage;

This would create a copy of the builtin content and then replace the image with your texture.

To load an image from your assets folder, just use any load function that the editor API provides. For example EditorGUIUtility.Load. For this method you should place your image in "Assets/Editor Default Resources/".

ps:

It looks like EditorGUIUtility.IconContent just uses EditorGUIUtility.Load under the hood, so it can even load images from your assets folder just by specifing the asset path. I haven't tried it yet, but it should actually work just fine.

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 alexanderameye · Mar 03, 2017 at 10:21 PM 1
Share

Hey! I used EditorGUIUtility.IconContent and put the icon files under Assets\Editor Default Resources\Icons and it worked perfectly! (Apart from some scale issues etc..)

Thank you so much, I see you answering a lot on my questions! You're doing a fantastic job!

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

64 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

Related Questions

How to show an icon in Hierarchy view 5 Answers

Initialising List array for use in a custom Editor 1 Answer

How to achieve proper inspector functionality (blue highlight of last tweaked) with elements from the GUI class (not from EditorGUI) 1 Answer

How do I get the GUI Icon to stretch? 1 Answer

why i'm not geting Toggle symbol when i apply fontstyle(GUIStyle)? 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