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);
                }
            }
        }
    改变自己
  • 相关阅读:
    sessionid如何产生?由谁产生?保存在哪里?
    springmvc原理
    java基础面试题
    mysql数据库去重复
    git安装和初次使用
    String的按值传递,java传参都是传值
    sublime Text3使用笔记
    git命令使用记录
    Git:错误:error:src refspec master does not match any
    java并发编程实战学习(3)--基础构建模块
  • 原文地址:https://www.cnblogs.com/sun-shadow/p/9324655.html
Copyright © 2011-2022 走看看