Пример #1
0
 // Token: 0x060002D9 RID: 729 RVA: 0x0001806C File Offset: 0x0001626C
 public static Texture2D BlitCrop(this Texture2D texture, Rect blitRect)
 {
     return(texture.Blit(blitRect, new[]
     {
         texture.width,
         texture.height
     }));
 }
Пример #2
0
        // Token: 0x060002D8 RID: 728 RVA: 0x00017F60 File Offset: 0x00016160
        public static Color[] GetColorSafe(this Texture2D texture, out int width, out int height)
        {
            width  = texture.width;
            height = texture.height;
            if (texture.width > texture.height)
            {
                width  = Math.Min(width, blitMaxDimensions);
                height = (int)(width * (texture.height / (float)texture.width));
            }
            else if (texture.height > texture.width)
            {
                height = Math.Min(height, blitMaxDimensions);
                width  = (int)(height * (texture.width / (float)texture.height));
            }
            else
            {
                width  = Math.Min(width, blitMaxDimensions);
                height = Math.Min(height, blitMaxDimensions);
            }

            var blitRect = new Rect(0f, 0f, width, height);
            var rtSize   = new[]
            {
                width,
                height
            };

            if (width == texture.width && height == texture.height)
            {
                try
                {
                    return(texture.GetPixels());
                }
                catch
                {
                    return(texture.Blit(blitRect, rtSize).GetPixels());
                }
            }

            var result = texture.Blit(blitRect, rtSize).GetPixels();

            return(result);
        }
Пример #3
0
        public static Texture2D Scale(this Texture2D that, int width, int height, ScaleMode mode)
        {
            var material = new Material(Shader.Find("LNE/Scale"));              // this wont work in play mode

            material.SetVector("_src_res", new Vector2(that.width, that.height));
            material.SetVector("_dst_res", new Vector2(width, height));
            material.SetInt("_mode", (int)mode);

            return(that.Blit(material, width, height));
        }
Пример #4
0
        /// <summary>
        /// Texture2D.GetPixels() method circumventing the read-write protection and taking into account <i>blitMaxDimensions</i>.
        /// </summary>
        /// <param name="texture">Any texture with/without read-write protection, of any size (but will be scaled to blitMaxDimensions if larger than those)</param>
        /// <param name="width">Final width of Color[]</param>
        /// <param name="height">Final height of Color[]</param>
        /// <returns>Color[] array after resizing to fit blitMaxDimensions</returns>
        public static Color[] GetColorSafe(this Texture2D texture, out int width, out int height)
        {
            width  = texture.width;
            height = texture.height;
            if (texture.width > texture.height)
            {
                width  = Math.Min(width, blitMaxDimensions);
                height = (int)((float)width * ((float)texture.height / (float)texture.width));
            }
            else if (texture.height > texture.width)
            {
                height = Math.Min(height, blitMaxDimensions);
                width  = (int)((float)height * ((float)texture.width / (float)texture.height));
            }
            else
            {
                width  = Math.Min(width, blitMaxDimensions);
                height = Math.Min(height, blitMaxDimensions);
            }

            Color[] color = null;

            var blitRect = new Rect(0, 0, width, height);
            var rtSize   = new [] { width, height };

            if (width == texture.width && height == texture.height)
            {
                try
                {
                    color = texture.GetPixels();
                }
                catch
                {
                    color = texture.Blit(blitRect, rtSize).GetPixels();
                }
            }
            else
            {
                color = texture.Blit(blitRect, rtSize).GetPixels();
            }
            return(color);
        }
Пример #5
0
        public static Texture2D Blit_Editor(this Texture2D that, Material material)
        {
            that.SaveAsPNG(UnityApp.ProjectPath + $"test_0.png");

            for (int i = 0; i < material.passCount; i++)
            {
                for (int j = 0; j < material.passCount; j++)
                {
                    var passName = material.GetPassName(j);
                    material.SetShaderPassEnabled(passName, i == j);
                }

                that = that.Blit(material);
                that.SaveAsPNG(UnityApp.ProjectPath + $"test_{material.GetPassName(i)}.png");
            }

            return(that);
        }
Пример #6
0
 public static Texture2D Blit(this Texture2D that, Material material)
 {
     return(that.Blit(material, that.width, that.height));
 }