unity 设置texture2d的格式

  最近需要设置2d texture的格式:

 

      写了个接口:

    private static void SetTextureImportFormat(UnityEngine.Object textureObject,
                                        int maxSize,
                                        bool isReadable,
                                        TextureImporterFormat pcFormat,
                                        TextureImporterFormat androidFormat,
                                        TextureImporterFormat iosFormat)
    {
        if (textureObject != null)
        {
            if (textureObject is Texture2D)
            {
                string path = AssetDatabase.GetAssetPath(textureObject);
                TextureImporter ti = TextureImporter.GetAtPath(path) as TextureImporter;
                ti.mipmapEnabled = false;
                ti.wrapMode = TextureWrapMode.Clamp;
                ti.textureType = TextureImporterType.Default;
                ti.filterMode = FilterMode.Point;
                ti.isReadable = isReadable;
                //--设置平台格式--
                TextureImporterPlatformSettings importerSettings_PC = new TextureImporterPlatformSettings();
                importerSettings_PC.overridden = true;
                importerSettings_PC.name = "Standalone";
                importerSettings_PC.textureCompression = TextureImporterCompression.Uncompressed;
                importerSettings_PC.maxTextureSize = maxSize;
                importerSettings_PC.format = pcFormat;

                TextureImporterPlatformSettings importerSettings_Andorid = new TextureImporterPlatformSettings();
                importerSettings_Andorid.overridden = true;
                importerSettings_Andorid.name = "Android";
                importerSettings_Andorid.textureCompression = TextureImporterCompression.Uncompressed;
                importerSettings_Andorid.maxTextureSize = maxSize;
                importerSettings_Andorid.format = androidFormat;

                TextureImporterPlatformSettings importerSettings_IOS = new TextureImporterPlatformSettings();
                importerSettings_IOS.overridden = true;
                importerSettings_IOS.name = "iPhone";
                importerSettings_IOS.textureCompression = TextureImporterCompression.Uncompressed;
                importerSettings_IOS.maxTextureSize = maxSize;
                importerSettings_IOS.format = iosFormat;
                //-----

                ti.SetPlatformTextureSettings(importerSettings_PC);
                ti.SetPlatformTextureSettings(importerSettings_Andorid);
                ti.SetPlatformTextureSettings(importerSettings_IOS);
                ti.SaveAndReimport();
                AssetDatabase.ImportAsset(path);
            }
        }
    }

 

转载于:https://www.cnblogs.com/sun-shadow/p/9324655.html

你可能感兴趣的:(unity 设置texture2d的格式)