为测试Untiy工程里Texture的Alpha对性能的压力,需要临时移除Unity工程里所有图片的Alpha通道,做测试对比。
这里有一个基本的技巧,当图片不存在Alpha通道时,就不需要处理,如何判断图片是否存在Alpha通道呢,Unity不存在直接的接口。但可以这么干:
1.
ti.textureFormat = TextureImporterFormat.AutomaticTruecolor;
AssetDatabase.ImportAsset(_relativeAssetPath);
AssetDatabase.ImportAsset(_relativeAssetPath);
2.
static bool IsNoAlphaTexture(Texture2D texture)
{
return texture.format == TextureFormat.RGB24;
}
{
return texture.format == TextureFormat.RGB24;
}
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using System.IO;
using System.Reflection;
public class RemoveAlphaChanel
{
[MenuItem("TextureTest/Remove Texture Alpha Chanel")]
static void ModifyTextures()
{
Debug.Log("Start Removing Alpha Chanel.");
string[] paths = Directory.GetFiles(Application.dataPath, "*.*", SearchOption.AllDirectories);
foreach (string path in paths)
{
if (!string.IsNullOrEmpty(path) && IsTextureFile(path)) //full name
{
RemoveTextureAlphaChanel(path);
}
}