Skip to content

Instantly share code, notes, and snippets.

@kamend kamend/AssetProcessing.cs
Last active Aug 8, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.