Skip to content

Instantly share code, notes, and snippets.

@GregLukosek
Last active May 23, 2023 05:12
Show Gist options
  • Save GregLukosek/a4d859cd84ecb442fb21 to your computer and use it in GitHub Desktop.
Save GregLukosek/a4d859cd84ecb442fb21 to your computer and use it in GitHub Desktop.
Custom Texture Importer for Unity
//Greg Lukosek 2015
//[email protected]
using UnityEngine;
using UnityEditor;
public class TexturePostProcessor : AssetPostprocessor
{
void OnPostprocessTexture(Texture2D texture)
{
TextureImporter importer = assetImporter as TextureImporter;
importer.anisoLevel = 0;
importer.filterMode = FilterMode.Bilinear;
importer.mipmapEnabled = false;
importer.spritePixelsPerUnit = 1f;
importer.textureFormat = TextureImporterFormat.AutomaticTruecolor;
Object asset = AssetDatabase.LoadAssetAtPath(importer.assetPath, typeof(Texture2D));
if (asset) {
EditorUtility.SetDirty(asset);
}
else {
texture.anisoLevel = 0;
texture.filterMode = FilterMode.Trilinear;
}
}
}
To use place it in Assets/Editor forlder in Unity. All imported textures will pick up the settings from the code automatically.
CDDL Licence, free to use, edit and share
Greg Lukosek
[email protected]
Twitter: @lukos86
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment