zoukankan      html  css  js  c++  java
  • 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);
                }
            }
        }
    改变自己
  • 相关阅读:
    用Java实现一个简单的DBMS(总结)
    Android小记(整理一下自己犯过的错误)
    在华为云上开启FTP服务并建立FTP站点来从本地向服务器发送和下载文件
    AS中使用真机调试时出现解析错误的问题
    AS中加载gradle时出现Gradle sync failed: Could not find com.android.tools.build:gradle.的错误
    解决AS加载gradle时出现的Could not find com.android.tools.build:gradle:3.5.0.的错误
    过滤器
    View的呈现
    Asp.net MVC Action同步异步执行
    Model验证
  • 原文地址:https://www.cnblogs.com/sun-shadow/p/9324655.html
Copyright © 2011-2022 走看看