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
2
Question by CiberX15 · Oct 01, 2013 at 04:43 AM · iconiconsitem pickupgame editor

Use editor icons in game?

Odd question, I am creating an RPG with a bunch of items that can go into the players inventory and should have icons. Now the way my inventory works I store a Transform of the item so that it can be spawned back into the game later. The objects are of course all prefabs, and in the unity editor they all have icons that appear to be isometric snapshots of the item in question. It would save me a ton of time and resources if I could use that automatically generated icon image in my inventory instead of having to make one for each and every single item in my game. Is this possible? and if so can I get it out of a transform?

Thanks in advance : )

Comment
Add comment · Show 6
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 tw1st3d · Oct 01, 2013 at 04:51 AM 0
Share

Good question, I'm interested in seeing a good response. I'm sure it'll come in handy later on.

avatar image CiberX15 · Oct 02, 2013 at 04:34 PM 0
Share

Should I assume that since this question has been largely forgotten there is simply no way of doing this : ?

avatar image Hoeloe · Oct 02, 2013 at 04:47 PM 0
Share

It's been a day, I wouldn't call that "largely forgotten".

avatar image CiberX15 · Oct 02, 2013 at 04:50 PM 0
Share

No one has ever accused me of being patient X P

THREE $$anonymous$$INUTES HAVE PASSED $$anonymous$$Y POST HAS BEEN FORGOTTEN AGAIN!!!!!!

X D

avatar image CiberX15 · Dec 03, 2013 at 09:52 PM 0
Share

Ok how about now, can it be considers largely forgotten now?

X P

Show more comments

2 Replies

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

Answer by felixpk · Dec 04, 2013 at 02:24 PM

 using UnityEditor;

 public GameObject tower;
 Texture2D icon1 = AssetPreview.GetAssetPreview(tower);

Thats all I needed to make it work, the big contra is, that these Thumbs have no Alpha channel :(

Comment
Add comment · Show 4 · 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 CiberX15 · Dec 04, 2013 at 02:43 PM 0
Share

That is excellent sir, exactly what I needed.

avatar image Hoeloe · Dec 04, 2013 at 03:25 PM 0
Share

You can't do that. UnityEditor isn't exported as part of the executable package, so you'll get linkage errors when you try to export the game if any file (other than Editor scripts) include objects from the UnityEditor namespace.

avatar image felixpk · Dec 04, 2013 at 03:43 PM 0
Share

Thanks for mentioning, but that isn't a problem either!

 Texture2D icon1 = AssetPreview.GetAssetPreview(tower);
         byte[] photoData = icon1.EncodeToPNG();
         File.WriteAllBytes(Application.dataPath + "/Tower.png",photoData);

I Save the Images in the Asset folder, now you can acces them

avatar image Hoeloe · Dec 04, 2013 at 04:18 PM 0
Share

You have to do that in an editor script, and then make use of the asset separately, but yes, that will work.

avatar image
0

Answer by burnill · Dec 04, 2013 at 12:30 PM

You can't sadly. The picture isn't an icon/ image but instead a live rendering of the object. The only way you can get an image of the icon would be the good old screenshot and crop method.

p.s. I've just seen this line which may work.

 var icon1 : Texture2D = AssetDatabase.GetCachedIcon("Assets/Buildings/Assembly1.prefab");
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 felixpk · Dec 04, 2013 at 12:50 PM 0
Share

The name `AssetDatabase' does not exist in the current context, any namespace I may forgot? It is: using UnityEditor;

avatar image felixpk · Dec 04, 2013 at 01:01 PM 0
Share

alt text

All I get from your code is this.. but thanks anyways!

And one thing: it does not return a Texture2D but a Texture!

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

19 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

Related Questions

How to use editor itons in game? 1 Answer

No Adaptive icon settings 0 Answers

Can user register for a game directly through the plugin? 0 Answers

Exported Mac App Icon is Distorted 1 Answer

GameObject Icon not saving 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