- Home /
GetAssetPreview Transparent background with higher resolution
Hi,
This is my current script.
I need to generate a Texture2D of my prefab models and this is the best way I have found till now. The image generated is low resoltion and also has a grey background.
Any help would be appreciated. Would be a plus if I can choose the angle of the generation.
[MenuItem("Alpha/Generate Texture2d", false, 101)]
public static void GenerateTexture2D()
{
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
if(System.IO.Path.GetExtension(path) == ".prefab")
{
Texture2D tex = AssetPreview.GetAssetPreview(Selection.activeGameObject);
tex.alphaIsTransparency = true;
byte[] bytes = tex.EncodeToPNG();
System.IO.File.WriteAllBytes(Application.dataPath + "/SavedScreen.png", bytes);
}
else
{
Debug.LogError("Asset Selected not Prefab");
}
}
Comment
Your answer
Follow this Question
Related Questions
How to generate a Texture2D of the thumbnail of a prefab? 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Combine Array of Sprites to Form One Sprite 0 Answers
Problem when loading texture from folder 0 Answers