public static void textureToTexture2D (Texture texture, Texture2D texture2D)
{
if (texture == null)
throw new ArgumentNullException ("texture");
if (texture2D == null)
throw new ArgumentNullException ("texture2D");
if (texture.width != texture2D.width || texture.height != texture2D.height)
throw new ArgumentException ("texture and texture2D need to be the same size.");
RenderTexture prevRT = RenderTexture.active;
if (texture is RenderTexture) {
RenderTexture.active = (RenderTexture)texture;
texture2D.ReadPixels (new UnityEngine.Rect (0f, 0f, texture.width, texture.height), 0, 0, false);
texture2D.Apply (false, false);
} else {
RenderTexture tempRT = RenderTexture.GetTemporary (texture.width, texture.height, 0, RenderTextureFormat.ARGB32);
Graphics.Blit (texture, tempRT);
RenderTexture.active = tempRT;
texture2D.ReadPixels (new UnityEngine.Rect (0f, 0f, texture.width, texture.height), 0, 0, false);
texture2D.Apply (false, false);
RenderTexture.ReleaseTemporary (tempRT);
}
RenderTexture.active = prevRT;
}
unity 把Texture转成Texture2D
最新推荐文章于 2024-08-12 09:41:57 发布