【Unity3D】不可读Texture资源的获取
直接上代码
1 // 创建一个与纹理大小相同的临时 RenderTexture 2 RenderTexture tmp = RenderTexture.GetTemporary( 3 texture.width, 4 texture.height, 5 0, 6 RenderTextureFormat.Default, 7 RenderTextureReadWrite.Linear); 8 9 10 // 将纹理上的像素 Blit 到 RenderTexture 11 Graphics.Blit(texture, tmp); 12 13 14 // 备份当前设置的 RenderTexture 15 RenderTexture previous = RenderTexture.active; 16 17 18 // 将当前的 RenderTexture 设置为我们创建的临时 19 RenderTexture.active = tmp; 20 21 22 // 创建一个新的可读 Texture2D 将像素复制到它 23 Texture2D myTexture2D = new Texture2D(texture.width, texture.height); 24 25 26 // 将像素从 RenderTexture 复制到新的 Texture 27 myTexture2D.ReadPixels(new Rect(0, 0, tmp.width, tmp.height), 0, 0); 28 myTexture2D.Apply(); 29 30 31 // 重置活动的 RenderTexture 32 RenderTexture.active = previous; 33 34 35 // 释放临时的RenderTexture 36 RenderTexture.ReleaseTemporary(tmp); 37 38 39 // “myTexture2D”现在具有与“texture”相同的像素,它是重新
实测可行
资源来源原文:https://support.unity.com/hc/en-us/articles/206486626-How-can-I-get-pixels-from-unreadable-textures-