近期需要通过代码获取texture的格式,尝试了以下方式:
1.
//通过unity内置的方法,在资源导入时获取texture的format
//但是拿到的是default状态下的
public class ChangeTextureSetting2 : AssetPostprocessor
{
void OnPostprocessTexture(Texture2D texture)
{
Debug.Log(texture.format);
}
}
2.
TextureImporter import = AssetImporter.GetAtPath(item.storagePath) as TextureImporter;
TextureImporterPlatformSettings importPlatform = import.GetPlatformTextureSettings("Android");
importPlatform.overridden = true;
Debug.Log(importPlatform.format);
第二种方式存在一些问题:
当Override for Android 没有勾选时获取到的format全部是automatic compressed,而没法拿到面板上显示的RGBA Compressed ETC@ 8 bits
只有当我手动将Override for Android 勾选时才能通过第二种代码拿到正确的format
请问怎么才能通过代码自动获得format?
(另外问一声CSDN提问的标签怎么添加的?只能看到一些默认的,没看到相关标签在哪)