public static void Scale(this Texture2D tex, int width, int height) { if (width <= 0 || height <= 0 || (width == tex.width && height == tex.height)) { return; } tex.MakeFormatWritable(); Color[] colors = Texture2DExtensions.ScaledPixels(tex.GetPixels(0), tex.width, tex.height, width, height); if (tex.Resize(width, height, tex.format, tex.mipmapCount > 1)) { tex.SetPixels(colors, 0); tex.Apply(tex.mipmapCount > 1, false); } }
public static Texture2D ScaledCopy(this Texture2D tex, int width, int height, bool mipMaps) { if (width <= 0 || height <= 0) { return(null); } if (width == tex.width && height == tex.height) { return(tex.GetCopy(0, 0, tex.width, tex.height, mipMaps)); } Color[] colors = Texture2DExtensions.ScaledPixels(tex.GetPixels(0), tex.width, tex.height, width, height); Texture2D texture2D = new Texture2D(width, height, Texture2DExtensions.GetWritableFormat(tex.format), mipMaps); texture2D.SetPixels(colors, 0); texture2D.Apply(mipMaps, false); return(texture2D); }