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);
            }
        }
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM