예제 #1
0
        public static void Convert(this TexFormatGroup newFormat, Texture2D tex)
        {
            string          path = AssetDatabase.GetAssetPath(tex);
            TextureImporter im   = AssetImporter.GetAtPath(path) as TextureImporter;

            if (im == null || tex.format == TextureFormat.Alpha8)
            {
                return;
            }
            bool changed = false;

            if (newFormat == TexFormatGroup.ASTC && !tex.format.IsASTC())
            {
                im.SetFormat(GetFormatFromLabel(tex, newFormat, tex.format.HasAlpha()));
                changed = true;
            }
            else if (newFormat == TexFormatGroup.ETC2 && !tex.format.IsETC2())
            {
                im.SetFormat(GetFormatFromLabel(tex, newFormat, tex.format.HasAlpha()));
                changed = true;
            }
            else if (newFormat == TexFormatGroup.PVRTC && !tex.format.IsPVRTC())
            {
                if (EditorUserBuildSettings.activeBuildTarget.ToRuntimePlatform().IsIos() &&
#pragma warning disable 0618
                    (im.GetFormat() == TextureImporterFormat.AutomaticCompressed || im.GetFormat() == TextureImporterFormat.AutomaticCrunched))
#pragma warning restore 0618
                {
                    // automatic is the same as PVRTC
                }
                else if (tex.format.HasAlpha())
                {
                    // PVRTC with alpha downgrades the image quality
//					im.textureFormat = TextureImporterFormat.PVRTC_RGB4;
//					changed = true;
                }
                else
                {
                    im.SetFormat(GetFormatFromLabel(tex, newFormat, tex.format.HasAlpha()));
                    changed = true;
                }
            }
            else if (newFormat == TexFormatGroup.ETC && !tex.format.IsETC())
            {
                if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android &&
#pragma warning disable 0618
                    (im.GetFormat() == TextureImporterFormat.AutomaticCompressed || im.GetFormat() == TextureImporterFormat.AutomaticCrunched))
#pragma warning restore 0618
                {
                    // automatic is the same as ETC
                }
                else if (tex.format.HasAlpha())
                {
                    // alpha is not supported in ETC format
                }
                else
                {
                    im.SetFormat(GetFormatFromLabel(tex, newFormat, tex.format.HasAlpha()));
                    changed = true;
                }
#pragma warning disable 0618
            }
            else if (newFormat == TexFormatGroup.AUTO && (im.GetFormat() != TextureImporterFormat.AutomaticCompressed && im.GetFormat() != TextureImporterFormat.AutomaticCrunched))
#pragma warning restore 0618
            {
                if (tex.format.HasAlpha())
                {
                    // compressing alpha
                }
                else
                {
                    im.SetFormat(GetFormatFromLabel(tex, newFormat, tex.format.HasAlpha()));
                    changed = true;
                }
            }
            if (!AssetConfig.TEX_NPOT && im.npotScale == TextureImporterNPOTScale.None && !tex.IsPOT())
            {
                im.npotScale = TextureImporterNPOTScale.ToNearest;
                changed      = true;
            }
            if (changed)
            {
                im.textureType = TextureImporterType.Default;
                im.isReadable  = false;
                AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport);
            }
        }
예제 #2
0
 protected override bool FilterImpl(TextureImporter importer, Texture tex)
 {
     return(importer.GetFormat() == texImportFormat);
 }