这个是我的代码片段。
local repacked_skin,output_material,output_atlas = self.collected_skin:GetRepackedSkin(
"repacked skin",
material
)
使用GetRepackedSkin函数生成的output_atlas的textureFormat默认使用的TextureFormat.RGBA32。但这个TextureFormat导致这个图片在我的Iphone设备上占用的内存很大(8M)。
但是,当我给GetRepackedSkin函数传入参数textureFormat=ASTC_4x4,代码如下
local repacked_skin,output_material,output_atlas = self.collected_skin:GetRepackedSkin(
"repacked skin",
material,
1024,
2,
CS.UnityEngine.TextureFormat.ASTC_4x4
)
这段代码会让我的骨骼显示异常,并且报错。

我不清楚是什么原因。我的目的是想让最终的图片占用的内存变小。我不想使用RGBA32,它太大了。有没有什么解决办法?

Related Discussions
...

不幸的是,创建压缩纹理并不是可以在运行时合理完成的事情。 压缩格式旨在快速读取,但设计为在离线过程中写入。 换句话说,这不是你想在手机上做的事情。 此限制会影响生成的打包纹理,理论上可以压缩源纹理。 但是,如果您只压缩源纹理而无法压缩生成的打包纹理,则对于使用的大小没有多大帮助,只会使生成的打包纹理质量变差。

该调用可能会引发异常,因为纹理区域无法自由地复制到压缩纹理或从压缩纹理复制,因为压缩纹理以例如块的形式工作。 4x4 像素。 因此,您只能复制到正好位于 4x4 网格上的区域,例如 如果 32x32 块位于位置“(0, 2)”,则该块会失败。



Unfortunately creating compressed textures is not something that can be done reasonably at runtime. Compression formats are designed to be quick to read but are designed to be written in an offline process. In other words, it's not something you want to do on a phone. This limitation affects the resulting packed texture, the source texture could theoretically be compressed. However, if you only compress the source texture but can't compress the resulting packed texture, it would not help much in regards to used size but only make the resulting packed texture bad in quality.

The call likely throws an exception because texture regions can't be freely copied to or from a compressed texture, as compressed textures work in blocks of e.g. 4x4 pixels. So you could only copy to regions that lie exactly on the 4x4 grid, making e.g. a 32x32 block fail if it's located at location (0, 2).