Skip to content

Instantly share code, notes, and snippets.

@talecrafter
Last active June 27, 2017 00:30
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talecrafter/94fc9a1e3a00cc9e477b784af90c17b4 to your computer and use it in GitHub Desktop.
Save talecrafter/94fc9a1e3a00cc9e477b784af90c17b4 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEditor;
using System.IO;
// example PostProcessor for adjusting automatic Sprite Import settings
// save this in any "Editor" Folder
public class SpriteImportProcessor : AssetPostprocessor
{
void OnPostprocessSprites(Texture2D texture, Sprite[] sprites)
{
TextureImporter importer = assetImporter as TextureImporter;
// only change sprite import settings on first import, so we can change those settings for individual files
string name = importer.assetPath.ToLower();
if (File.Exists(AssetDatabase.GetTextMetaFilePathFromAssetPath(name)))
{
return;
}
// adjust values for pixel art
importer.spritePixelsPerUnit = 100;
importer.mipmapEnabled = false;
importer.filterMode = FilterMode.Point;
importer.textureFormat = TextureImporterFormat.AutomaticTruecolor;
// access the TextureImporterSettings to change the spriteAlignment value
TextureImporterSettings textureSettings = new TextureImporterSettings();
importer.ReadTextureSettings(textureSettings);
textureSettings.spritePivot = new Vector2(0.5f, 0f);
textureSettings.spriteAlignment = (int)SpriteAlignment.BottomCenter;
importer.SetTextureSettings(textureSettings);
importer.SaveAndReimport();
}
}
@chuckbergeron
Copy link

Slick! Thanks for sharing this Stephan 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment