public static Texture2D CopyTexture(Texture src, TextureImportTypes textureType, Material material) { Texture2D dst = null; RenderTextureReadWrite colorSpace = textureType.GetColorSpace(); var renderTexture = new RenderTexture(src.width, src.height, 0, RenderTextureFormat.ARGB32, colorSpace); using (var scope = new ColorSpaceScope(colorSpace)) { if (material != null) { Graphics.Blit(src, renderTexture, material); } else { Graphics.Blit(src, renderTexture); } } dst = new Texture2D(src.width, src.height, TextureFormat.ARGB32, false, colorSpace == RenderTextureReadWrite.Linear); dst.ReadPixels(new Rect(0, 0, src.width, src.height), 0, 0); dst.name = src.name; dst.anisoLevel = src.anisoLevel; dst.filterMode = src.filterMode; dst.mipMapBias = src.mipMapBias; dst.wrapMode = src.wrapMode; dst.wrapModeU = src.wrapModeU; dst.wrapModeV = src.wrapModeV; dst.wrapModeW = src.wrapModeW; dst.Apply(); RenderTexture.active = null; if (Application.isEditor) { GameObject.DestroyImmediate(renderTexture); } else { GameObject.Destroy(renderTexture); } return(dst); }
public static Texture2D CopyTexture(Texture src, TextureImportTypes textureType, Material material) { return(CopyTexture(src, textureType.GetColorSpace(), material)); }