- Home /
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 : )
Good question, I'm interested in seeing a good response. I'm sure it'll come in handy later on.
Should I assume that since this question has been largely forgotten there is simply no way of doing this : ?
It's been a day, I wouldn't call that "largely forgotten".
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
Ok how about now, can it be considers largely forgotten now?
X P
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 :(
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.
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
You have to do that in an editor script, and then make use of the asset separately, but yes, that will work.
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");
The name `AssetDatabase' does not exist in the current context, any namespace I may forgot? It is: using UnityEditor;
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
Follow this Question
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