close

 

 TextureImporter textureImporter = AssetImporter.GetAtPath(aPath) as TextureImporter;
                int aMaxTextureSize;
                TextureImporterFormat aTextureImporterFormat;
                int aCompressQuality;

                int aDefaultMaxTextureSize;
                textureImporter.GetPlatformTextureSettings("Default", out aDefaultMaxTextureSize, out aTextureImporterFormat, out aCompressQuality);


                TextureImporterPlatformSettings aImporterSettings = textureImporter.GetPlatformTextureSettings("Standalone");
                //TextureImporterPlatformSettings aImporterSettings = new TextureImporterPlatformSettings();
                if(textureImporter.textureType == TextureImporterType.SingleChannel)
                {
                    if (aTextureImporterFormat != TextureImporterFormat.Alpha8)
                        aImporterSettings.format = TextureImporterFormat.Alpha8;
                    else
                        continue;
                }
                else if (textureImporter.textureType == TextureImporterType.NormalMap)
                {
                    if (aTextureImporterFormat != TextureImporterFormat.DXT5)
                        aImporterSettings.format = TextureImporterFormat.DXT5;
                    else
                        continue;
                }
                else if (textureImporter.alphaSource == TextureImporterAlphaSource.FromGrayScale)
                {
                    Debug.Log("沒有 Alpha=" + aPath);
                    //沒有Alpha
                    if (aTextureImporterFormat != TextureImporterFormat.DXT1)
                        aImporterSettings.format = TextureImporterFormat.DXT1;
                    else
                        continue;
                }
                else if (textureImporter.alphaSource == TextureImporterAlphaSource.FromInput)
                {
                    Debug.Log("有 Alpha=" + aPath);
                    //有Alpha
                    if (aTextureImporterFormat != TextureImporterFormat.DXT5)
                        aImporterSettings.format = TextureImporterFormat.DXT5;
                    else
                        continue;
                }
                else
                {
                    Debug.LogWarning("不做事 = " + aPath);
                    continue;
                }
                   

                aImporterSettings.overridden = true;
                aImporterSettings.compressionQuality = 100;
                aImporterSettings.resizeAlgorithm = TextureResizeAlgorithm.Bilinear;
                aImporterSettings.textureCompression = (TextureImporterCompression)aCompressQuality;
                aImporterSettings.maxTextureSize = aDefaultMaxTextureSize;
                textureImporter.SetPlatformTextureSettings(aImporterSettings);
                textureImporter.SaveAndReimport();
                AssetDatabase.ImportAsset(aPath);

 


               

arrow
arrow
    全站熱搜

    GABY 發表在 痞客邦 留言(0) 人氣()