首页 > 代码库 > 判断资源贴图是否有alpha
判断资源贴图是否有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); } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。