ActiveTextureManagement.TextureConverter.Resize C# (CSharp) Метод

Resize() публичный статический Метод

public static Resize ( TextureInfoWrapper texture, int width, int height, bool mipmaps, bool convertToNormalFormat ) : void
texture TextureInfoWrapper
width int
height int
mipmaps bool
convertToNormalFormat bool
Результат void
        public static void Resize(TextureInfoWrapper texture, int width, int height, bool mipmaps, bool convertToNormalFormat)
        {
            ActiveTextureManagement.DBGLog("Resizing...");
            Texture2D tex = texture.texture;
            TextureFormat format = tex.format;
            if (texture.isNormalMap)
            {
                format = TextureFormat.ARGB32;
            }
            else if (format == TextureFormat.DXT1 || format == TextureFormat.RGB24)
            {
                format = TextureFormat.RGB24;
            }
            else
            {
                format = TextureFormat.RGBA32;
            }

            Color32[] pixels = tex.GetPixels32();
            if (convertToNormalFormat)
            {
                ConvertToUnityNormalMap(pixels);
            }

            Color32[] newPixels = ResizePixels(pixels, tex.width, tex.height, width, height);
            tex.Resize(width, height, format, mipmaps);
            tex.SetPixels32(newPixels);
            tex.Apply(mipmaps);
        }

Usage Example

Пример #1
0
        public static void IMGToTexture(TexInfo Texture, bool mipmaps, bool isNormalFormat)
        {
            TextureInfoWrapper texture = Texture.texture;

            TextureConverter.InitImageBuffer();
            FileStream imgStream = new FileStream(Texture.filename, FileMode.Open, FileAccess.Read);

            imgStream.Position = 0;
            imgStream.Read(imageBuffer, 0, MAX_IMAGE_SIZE);
            imgStream.Close();

            Texture2D tex = texture.texture;

            tex.LoadImage(imageBuffer);
            bool convertToNormalFormat = texture.isNormalMap && !isNormalFormat ? true : false;
            bool hasMipmaps            = tex.mipmapCount == 1 ? false : true;

            if (Texture.loadOriginalFirst)
            {
                Texture.Resize(tex.width, tex.height);
            }
            TextureFormat format = tex.format;

            if (texture.isNormalMap)
            {
                format = TextureFormat.ARGB32;
            }
            if (Texture.needsResize)
            {
                TextureConverter.Resize(texture, Texture.resizeWidth, Texture.resizeHeight, mipmaps, convertToNormalFormat);
            }
            else if (convertToNormalFormat || hasMipmaps != mipmaps || format != tex.format)
            {
                Color32[] pixels = tex.GetPixels32();
                if (convertToNormalFormat)
                {
                    for (int i = 0; i < pixels.Length; i++)
                    {
                        pixels[i].a = pixels[i].r;
                        pixels[i].r = pixels[i].g;
                        pixels[i].b = pixels[i].g;
                    }
                }
                if (tex.format != format || hasMipmaps != mipmaps)
                {
                    tex.Resize(tex.width, tex.height, format, mipmaps);
                }
                tex.SetPixels32(pixels);
                tex.Apply(mipmaps);
            }
        }