Skip to content

Instantly share code, notes, and snippets.

@kamend
Last active August 8, 2016 13:29
Show Gist options
  • Save kamend/6a6dd80b233079b6e101 to your computer and use it in GitHub Desktop.
Save kamend/6a6dd80b233079b6e101 to your computer and use it in GitHub Desktop.
Unity: An example how to set different Texture options based on the import directory. Copy this in the Editor folder.
using UnityEngine;
using UnityEditor;
public enum TextureType {
NONE = -1,
GUI = 0,
CHARACTERS = 1
}
public class AssetProcessing : AssetPostprocessor {
public static int pixelsPerUnits = 100;
public void OnPreprocessTexture() {
TextureImporter texImport = assetImporter as TextureImporter;
// default options
texImport.mipmapEnabled = false;
texImport.maxTextureSize = 2048;
TextureImporterSettings tis = new TextureImporterSettings();
texImport.ReadTextureSettings( tis );
TextureType t = GetTexType( assetPath );
switch (t) {
case TextureType.GUI:
// mark as Sprite
texImport.textureType = TextureImporterType.Sprite;
// SpriteAlignment
tis.spriteAlignment = (int)SpriteAlignment.BottomCenter;
// Pixels per Units
tis.spritePixelsPerUnit = AssetProcessing.pixelsPerUnits;
// Texture format
tis.textureFormat = TextureImporterFormat.RGBA32;
texImport.SetTextureSettings( tis );
break;
case TextureType.CHARACTER:
break;
}
}
public TextureType GetTexType( string assetPath ) {
if( assetPath.Contains( "Textures/GUI" ) ) {
return TextureType.GUI;
}
if( assetPath.Contains( "Textures/Characters" ) ) {
return TextureType.CHARACTERS;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment