码迷,mamicode.com
首页 > 其他好文 > 详细

判断资源贴图是否有alpha

时间:2014-05-28 20:28:19      阅读:438      评论:0      收藏:0      [点我收藏+]

标签:style   c   class   blog   code   java   

bubuko.com,布布扣
/*
  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); 
    }
}
bubuko.com,布布扣

 

判断资源贴图是否有alpha,布布扣,bubuko.com

判断资源贴图是否有alpha

标签:style   c   class   blog   code   java   

原文地址:http://www.cnblogs.com/softimagewht/p/3754721.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!