日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

Unity中如何计算带minimap的贴图资源的大小

發(fā)布時間:2025/7/25 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Unity中如何计算带minimap的贴图资源的大小 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

///
<summary>/// 計算貼圖大小,包含mipmap內(nèi)存的疊加/// </summary>/// <param name="tTexture"></param>/// <returns></returns>public static int CalculateTextureSizeBytes(Texture tTexture){int tWidth = tTexture.width;int tHeight = tTexture.height;if (tTexture is Texture2D){Texture2D tTex2D = tTexture as Texture2D;int bitsPerPixel = GetBitsPerPixel(tTex2D.format);int mipMapCount = tTex2D.mipmapCount;int mipLevel = 1;int tSize = 0;while (mipLevel <= mipMapCount){tSize += tWidth * tHeight * bitsPerPixel / 8;tWidth = tWidth / 2;tHeight = tHeight / 2;mipLevel++;}return tSize;}return 0;}/// <summary>/// 計算貼圖大小,包含mipmap內(nèi)存的疊加,指定貼圖格式/// </summary>/// <param name="tTexture"></param>/// <returns></returns>public static int CalculateTextureSizeBytesByFormat(Texture tTexture, TextureImporterFormat format){int tWidth = tTexture.width;int tHeight = tTexture.height;if (tTexture is Texture2D){Texture2D tTex2D = tTexture as Texture2D;if (TextureImporterFormat.Automatic == format){Debug.LogError("------------------>有貼圖格式未設(shè)置: 貼圖名稱:" + tTexture.name);}int bitsPerPixel = GetBitsPerPixelForImportFormat(format);int mipMapCount = tTex2D.mipmapCount;int mipLevel = 1;int tSize = 0;while (mipLevel <= mipMapCount){tSize += tWidth * tHeight * bitsPerPixel / 8;tWidth = tWidth / 2;tHeight = tHeight / 2;mipLevel++;}return tSize;}return 0;}/// <summary>/// 獲取對應(yīng)個是貼圖的位大小/// </summary>/// <param name="format"></param>/// <returns></returns>public static int GetBitsPerPixel(TextureFormat format){switch (format){case TextureFormat.Alpha8: // Alpha-only texture format.return 8;case TextureFormat.ARGB4444: // A 16 bits/pixel texture format. Texture stores color with an alpha channel.return 16;case TextureFormat.RGBA4444: // A 16 bits/pixel texture format.return 16;case TextureFormat.RGB24: // A color texture format.return 24;case TextureFormat.RGBA32: //Color with an alpha channel texture format.return 32;case TextureFormat.ARGB32: //Color with an alpha channel texture format.return 32;case TextureFormat.RGB565: // A 16 bit color texture format.return 16;case TextureFormat.DXT1: // Compressed color texture format.return 4;case TextureFormat.DXT5: // Compressed color with alpha channel texture format.return 8;case TextureFormat.PVRTC_RGB2:// PowerVR (iOS) 2 bits/pixel compressed color texture format.return 2;case TextureFormat.PVRTC_RGBA2:// PowerVR (iOS) 2 bits/pixel compressed with alpha channel texture formatreturn 2;case TextureFormat.PVRTC_RGB4:// PowerVR (iOS) 4 bits/pixel compressed color texture format.return 4;case TextureFormat.PVRTC_RGBA4:// PowerVR (iOS) 4 bits/pixel compressed with alpha channel texture formatreturn 4;case TextureFormat.ETC_RGB4:// ETC (GLES2.0) 4 bits/pixel compressed RGB texture format.return 4;case TextureFormat.ETC2_RGBA8:// ATC (ATITC) 8 bits/pixel compressed RGB texture format.return 8;case TextureFormat.BGRA32:// Format returned by iPhone camerareturn 32;}return 0;}public static int GetBitsPerPixelForImportFormat(TextureImporterFormat format){switch (format){case TextureImporterFormat.Alpha8: // Alpha-only texture format.return 8;case TextureImporterFormat.RGB24: // A color texture format.return 24;case TextureImporterFormat.RGBA32: //Color with an alpha channel texture format.return 32;case TextureImporterFormat.ARGB32: //Color with an alpha channel texture format.return 32;case TextureImporterFormat.RGBA16: // A 16 bit color texture format.return 16;case TextureImporterFormat.RGB16: // A 16 bit color texture format.return 16;case TextureImporterFormat.DXT1: // Compressed color texture format.return 4;case TextureImporterFormat.DXT5: // Compressed color with alpha channel texture format.return 8;case TextureImporterFormat.PVRTC_RGB2:// PowerVR (iOS) 2 bits/pixel compressed color texture format.return 2;case TextureImporterFormat.PVRTC_RGBA2:// PowerVR (iOS) 2 bits/pixel compressed with alpha channel texture formatreturn 2;case TextureImporterFormat.PVRTC_RGB4:// PowerVR (iOS) 4 bits/pixel compressed color texture format.return 4;case TextureImporterFormat.PVRTC_RGBA4:// PowerVR (iOS) 4 bits/pixel compressed with alpha channel texture formatreturn 4;case TextureImporterFormat.ETC_RGB4:// ETC (GLES2.0) 4 bits/pixel compressed RGB texture format.return 4;case TextureImporterFormat.ETC2_RGB4:// ETC (GLES3.0) 4 bits/pixel compressed RGB texture format.return 4;case TextureImporterFormat.ETC2_RGBA8:// ETC (GLES3.0) 8 bits/pixel compressed RGBA texture format.return 8;case TextureImporterFormat.Automatic:// 沒有設(shè)置貼圖格式,默認(rèn)給4bit.return 4;}return 0;}

?

轉(zhuǎn)載于:https://www.cnblogs.com/hengsoft/p/10289647.html

總結(jié)

以上是生活随笔為你收集整理的Unity中如何计算带minimap的贴图资源的大小的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。