设置Texture Android 识别格式

Unity 安卓的Testure 读取格式设置

为Pc制作的人物模型,在安卓环境下识别可能会出错。主要原因是Texture格式不对。
相应的Ios其实也有同样的问题。

解决办法

// An highlighted block
#if UNITY_ANDROID || UNITY_IOS
        string path = AssetDatabase.GetAssetPath(Mesh);
        AssetImporter asset = AssetImporter.GetAtPath(path);
        TextureImporter textureImporter = asset as TextureImporter;
        if (textureImporter != null)
        {
    
    
            SetTextureFormat(textureImporter);
            textureImporter.SaveAndReimport();
        }
        AssetDatabase.Refresh();
#endif
// 修改格式
public static void SetTextureFormat(TextureImporter textureImporter)
    {
    
    
        textureImporter.isReadable = true;
#if UNITY_IOS
        TextureImporterPlatformSettings ios = textureImporter.GetPlatformTextureSettings("iPhone");
        ios.overridden = true;
        ios.format = TextureImporterFormat.RGBAHalf;
        textureImporter.SetPlatformTextureSettings(ios);
#elif UNITY_ANDROID
        TextureImporterPlatformSettings android = textureImporter.GetPlatformTextureSettings("Android");
        android.overridden = true;
        android.format = TextureImporterFormat.RGBAHalf;
        textureImporter.SetPlatformTextureSettings(android);
#endif
    }

注意
安卓需要修改ColorSpace

// 修改ColorSpace
#if UNITY_ANDROID
                            PlayerSettings.colorSpace = ColorSpace.Linear;
                            AssetDatabase.Refresh();
#endif

关于具体原因:
在这里插入图片描述
原文链接

猜你喜欢

转载自blog.csdn.net/TaoDuanYi/article/details/127124647