Last active
June 27, 2017 00:30
-
-
Save talecrafter/94fc9a1e3a00cc9e477b784af90c17b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Slick! Thanks for sharing this Stephan 😀