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);
                }
            }
        }
    改变自己
  • 相关阅读:
    数据库语句学习(union语句)
    终于开通博客了啦
    Winform用Post方式打开IE
    Winform webbrowser 隐藏 html 元素
    MVC 附件在线预览
    典型用户和场景
    我的第一篇博客01
    大数据算法摘录
    mac下查看端口占用情况
    tomcat的运行脚本
  • 原文地址:https://www.cnblogs.com/sun-shadow/p/9324655.html
Copyright © 2011-2022 走看看