Пример #1
0
        public static Texture2D GetCopy(this Texture2D tex, int x, int y, int w, int h, bool mipMaps)
        {
            Texture2D texture2D = new Texture2D(w, h, Texture2DExtensions.GetWritableFormat(tex.format), mipMaps);

            texture2D.SetPixels(tex.GetPixels(x, y, w, h, 0), 0);
            texture2D.Apply(mipMaps, false);
            return(texture2D);
        }
Пример #2
0
        public static void MakeFormatWritable(this Texture2D tex)
        {
            TextureFormat format         = tex.format;
            TextureFormat writableFormat = Texture2DExtensions.GetWritableFormat(tex.format);

            if (writableFormat != format)
            {
                Color[] pixels = tex.GetPixels(0);
                tex.Resize(tex.width, tex.height, writableFormat, tex.mipmapCount > 1);
                tex.SetPixels(pixels, 0);
                tex.Apply(tex.mipmapCount > 1, false);
            }
        }
Пример #3
0
 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);
     }
 }
Пример #4
0
        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);
        }