- Home /
Is there a way to import png images with TextureType = GUI automatically?
I am building a multiple choice quiz engine for my game. All questions and answer choices are imported into a Resources folder in the Unity Editor from png files. Unity sets the TextureType to 'Texture' by default, but this scales the image to power of 2 dimensions and has mipmap data, etc. The end result is that these images render much better with the TextureType set to 'GUI'. I can't really do this manually because I'm importing over 20,000 images at a time.
Is there a way to tell Unity to import these png images with the TextureType set to 'GUI' or is there a way via editor script or something to change them all programmatically?
Thanks!
Answer by OP_toss · Aug 23, 2013 at 06:16 PM
Thanks, OP_toss. Here's what I came up with. It appears to be working well.
using UnityEngine;
using UnityEditor;
public class ItemPostProcessor : AssetPostprocessor
{
void OnPreprocessTexture()
{
TextureImporter importer = assetImporter as TextureImporter;
if(importer.assetPath.Contains("pack_") && importer.assetPath.Contains(".png"))
importer.textureType = TextureImporterType.GUI;
}
}