Last active
August 8, 2016 13:29
-
-
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.
This file contains 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; | |
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