コガネブログ

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

【Unity】OnPreprocessTextureでテクスチャのサイズを取得する方法

  • Unity 5.4.3f1
public class TextureAssetPostProcessor : AssetPostprocessor
{
    private void OnPreprocessTexture()
    {
        var impoter     = assetImporter as TextureImporter;
        var size        = new object[ 2 ] { 0, 0 };
        var method      = typeof( TextureImporter ).GetMethod( "GetWidthAndHeight", BindingFlags.NonPublic | BindingFlags.Instance );
        method.Invoke( impoter, size );
        
        var width  = ( int )size[ 0 ];
        var height = ( int )size[ 1 ]; 
    }
}