我有一些要转换为 .png 图像文件的 AssetBundle。
它们是 Texture2D Assets ,但问题是它们不是 Read Enable,当
我尝试使用
将它们转换为 PNG
var _bytes = _texture2d.EncodeToPNG();
命令,我收到以下错误消息:
Texture 'name of a texture' is not readable, the texture memory can not be accessed from scripts. You can make the texture readable in the
Texture Import Settings.
我真的无法访问纹理导入设置,因为它们来自 Assets 包,而且一切都是用代码制作的。
有人对此有解决方法吗?
谢谢
这是一个可行的解决方案:
public static void SetTextureImporterFormat( Texture2D texture, bool isReadable)
{
if ( null == texture ) return;
string assetPath = AssetDatabase.GetAssetPath( texture );
var tImporter = AssetImporter.GetAtPath( assetPath ) as TextureImporter;
if ( tImporter != null )
{
tImporter.textureType = TextureImporterType.Advanced;
tImporter.isReadable = isReadable;
AssetDatabase.ImportAsset( assetPath );
AssetDatabase.Refresh();
}
}