31 lines
1.3 KiB
C#
31 lines
1.3 KiB
C#
using System.IO;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using System.Linq;
|
|
|
|
public class RemoveTexAlpha
|
|
{
|
|
[MenuItem("Test/Remove Texture Alpha")]
|
|
public static void ConvertAlpha()
|
|
{
|
|
var texturePaths = from assetPath in AssetDatabase.GetAllAssetPaths()
|
|
where assetPath.StartsWith("Assets/_Test/Texture")
|
|
where ".png" == Path.GetExtension(assetPath)
|
|
select assetPath;
|
|
var root = Application.dataPath.Open("_Test/Convert");
|
|
if (!Directory.Exists(root))
|
|
Directory.CreateDirectory(root);
|
|
foreach (var assetPath in texturePaths)
|
|
{
|
|
var texture = AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath);
|
|
var colors = texture.GetPixels();
|
|
for (var x = 0; x < colors.Length; x++)
|
|
colors[x].a = 1f;
|
|
var newTexture = new Texture2D(texture.width, texture.height, TextureFormat.RGBA32, false);
|
|
newTexture.SetPixels(colors);
|
|
var newPath = root.Open(Path.GetFileName(assetPath));
|
|
File.WriteAllBytes(newPath, newTexture.EncodeToPNG());
|
|
Debug.LogWarning(string.Format("Remove alpha for {0} to {1}", assetPath, newPath.Substring(Application.dataPath.MoveUp().Length + 1)));
|
|
}
|
|
}
|
|
} |