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);
                }
            }
        }
    改变自己
  • 相关阅读:
    return 与 exit() 的区别
    RtlInitUnicodeString
    计算机网络 学习笔记-概论
    STM32学习笔记(五) USART异步串行口输入输出(轮询模式)
    STM32学习笔记(四) RCC外设的学习和理解
    简单RTOS学习(一) uc/os-II 工程模板建立
    web前端学习(一) html+js实现文本框背景及只读属性修改
    TCP/IP协议学习(一) LWIP实现网络远程IAP下载更新
    STM32学习笔记(三) STM32的GPIO的深入学习
    STM32学习笔记(二) 基于STM32-GPIO的流水灯实现
  • 原文地址:https://www.cnblogs.com/sun-shadow/p/9324655.html
Copyright © 2011-2022 走看看