zoukankan      html  css  js  c++  java
  • 判断资源贴图是否有alpha

    /*
      modfly selected textures`s maxSize and ImportFormat
      bool hasAlpha = true;
      if(hasAlpha)then(texture.size/2 and trueColor)else(16bit)
    
      2014.05.27
    */
    
    using UnityEngine;
    using System.Collections;
    using UnityEditor;
    public class modflyTextures : ScriptableObject{
    
        [MenuItem ("Custom/modflyTextures")]
        static void processTexture_Auto() { 
            processTexture();
        }
    
        static void processTexture() { 
            
            Object[] textures = GetSelectedTextures(); 
            Selection.objects = new Object[0];
            foreach (Texture2D tex in textures)  {
                string path = AssetDatabase.GetAssetPath(tex); 
                TextureImporter importerTexture = AssetImporter.GetAtPath(path) as TextureImporter; 
    
                if(importerTexture.DoesSourceTextureHaveAlpha() ==  true){
                    if(tex.width >= tex.height )
                        importerTexture.maxTextureSize = tex.width/2;
                    else importerTexture.maxTextureSize = tex.height/2;
                    
                    importerTexture.textureFormat = TextureImporterFormat.AutomaticTruecolor;
                }else{
                    if(tex.width >= tex.height )
                        importerTexture.maxTextureSize = tex.width;
                    else importerTexture.maxTextureSize = tex.height;
    
                    importerTexture.textureFormat = TextureImporterFormat.AutomaticCompressed;
                }
                AssetDatabase.ImportAsset(path); 
            }
        }
    
        static Object[] GetSelectedTextures() 
        { 
            return Selection.GetFiltered(typeof(Texture2D), SelectionMode.DeepAssets); 
        }
    }
  • 相关阅读:
    洛谷 P5043 树的同构 题解
    CF 1178E Archaeology 题解
    UVA 1642 MagicalGCD 题解
    洛谷 P3919 可持久化线段树 题解
    SPOJ 4003 Phone List 题解
    OI/ACM最全卡常大招
    洛谷 P3368 树状数组 题解
    逆序对
    洛谷 U78696 图书馆馆长的考验 题解
    原创 疲劳炉石传说
  • 原文地址:https://www.cnblogs.com/softimagewht/p/3754721.html
Copyright © 2011-2022 走看看