- Home /
Import Textures with Texture Type set to Sprite by Default
The title says it all.
I am currently importing a lot of textures for the UI and having to set them to Sprite in the Editor after importing them.
Is there a way to have the Texture Type setting default to Sprite UI on import?
(I will use a sprite sheet in the future but I am prototyping atm so doing this a lot while checking new items)
Thanks
Been about 24hours so giving this a bump to see if anyone around now knows.
Answer by akaBase · Oct 25, 2019 at 02:24 PM
Incase anyone else wants to know I was given a couple of answers on the Unity Forum
(I have found it a better place to ask questions).
1: have the project setup to be a 2D Project.
This is not ideal for all scenarios and not the option I went with.
2: Use the AssetPostprocessor to set what happens to different objects when imported.
The example in the docs suggests using folder path names to set what happens but for me and importing textures I decided on a naming scheme where the start of the filename declares what type of texture it is, see example code below.
public class TextureImport : AssetPostprocessor
{
void OnPreprocessTexture()
{
TextureImporter textureImporter = (TextureImporter)assetImporter;
textureImporter.maxTextureSize = 512;
textureImporter.textureCompression = TextureImporterCompression.CompressedHQ;
int startIndex = assetPath.LastIndexOf("/") + 1;
string assetName = assetPath.Substring(startIndex, assetPath.Length - startIndex);
if (assetName.StartsWith("s_"))
{
textureImporter.textureType = TextureImporterType.Sprite;
}
else if (assetName.StartsWith("t_"))
{
textureImporter.textureType = TextureImporterType.Default;
}
else if (assetName.StartsWith("n_"))
{
textureImporter.convertToNormalmap = true;
}
}
}
This can easily be changed for project specifics and hope it helps anyone else that has been having this issue.
Your answer
Follow this Question
Related Questions
Imported sprites are not pixel perfect 0 Answers
FLAPPY BIRD CLONE 1 Answer
Imported texture changes its size when set to Sprite(2d and UI) type 0 Answers
How to stop gradient banding? 2 Answers