コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】OnPreprocessTextureでテクスチャフォーマットにETCやPVRTCを設定する方法

  • Unity 5.4.3f1
public class TextureAssetPostProcessor : AssetPostprocessor
{
    private void OnPreprocessTexture()
    {
        var impoter             = assetImporter as TextureImporter;
        var maxTextureSize      = 2048;
        var compressionQuality  = 50;
        
        impoter.SetPlatformTextureSettings
        ( 
            platform            : "Android", 
            maxTextureSize      : maxTextureSize, 
            textureFormat       : TextureImporterFormat.ETC_RGB4, 
            compressionQuality  : compressionQuality,
            allowsAlphaSplit    : false 
        );
        
        impoter.SetPlatformTextureSettings
        ( 
            platform            : "iPhone",
            maxTextureSize      :  maxTextureSize, 
            textureFormat       :  TextureImporterFormat.PVRTC_RGB4, 
            compressionQuality  :  compressionQuality, 
            allowsAlphaSplit    :  false 
        );
    }
}

参考サイト様