统一更改Texture2D格式
我有一个Textured2D
加载,在ETC_RGB4
表示如何将其更改为另一种格式? 说RGBA32
。 基本上我想从3个通道切换到4个通道,每通道4个比特切换到每通道8个通道。
谢谢
您可以在运行时更改纹理格式。
1.创建新的空Texture2D
并将RGBA32
提供给TextureFormat
参数。 这将使用RGBA32
格式创建一个空纹理。
2.使用 Texture2D.GetPixels
获取ETC_RGB4
格式的旧纹理的像素,然后使用Texture2D.SetPixels
将这些像素放入#1中新创建的纹理中。
3.Call Texture2D.Apply
应用更改。 而已。
一个简单的扩展方法:
public static class TextureHelperClass { public static Texture2D ChangeFormat(this Texture2D oldTexture, TextureFormat newFormat) { //Create new empty Texture Texture2D newTex = new Texture2D(2, 2, newFormat, false); //Copy old texture pixels into new one newTex.SetPixels(oldTexture.GetPixels()); //Apply newTex.Apply(); return newTex; } }
用法 :
public Texture2D theOldTextue; // Update is called once per frame void Start() { Texture2D RGBA32Texture = theOldTextue.ChangeFormat(TextureFormat.RGBA32); }