2using System.Runtime.CompilerServices;
18 [MethodImpl(MethodImplOptions.AggressiveInlining)]
19 private static int Index(
int row,
int column,
int columns)
21 return row * columns + column;
32 var width = texture.width;
33 var height = texture.height;
34 var pixels = texture.GetRawTextureData<Color32>();
36 for (
int i = 1; i < height - 1; i++)
38 pixels[
Index(i, width - 1, width)] = pixels[
Index(i, width - 2, width)];
39 pixels[
Index(i, 0, width)] = pixels[
Index(i, 1, width)];
42 for (
int j = 0; j < width; j++)
44 pixels[
Index(height - 1, j, width)] = pixels[
Index(height - 2, j, width)];
45 pixels[
Index(0, j, width)] = pixels[
Index(1, j, width)];
55 public static void Fill(Texture2D texture, Color32 color)
59 var pixels = texture.GetRawTextureData<Color32>();
61 for (
int i = 0; i < pixels.Length; i++)
74 public static void Fill(Texture2D texture, Color32 color, RectInt area)
78 var pixels = texture.GetRawTextureData<Color32>();
79 var textureWidth = texture.width;
81 for (
int i = 0; i < area.height; i++)
85 for (
int j = 0; j < area.width; j++)
87 var column = j + area.x;
88 pixels[
Index(row, column, textureWidth)] = color;
103 var pixels = texture.GetRawTextureData<Color32>();
105 for (
int i = 0; i < pixels.Length; i++)
118 public static void CompositeFill(Texture2D texture, Color color, RectInt area)
122 var pixels = texture.GetRawTextureData<Color32>();
123 var textureWidth = texture.width;
125 for (
int i = 0; i < area.height; i++)
127 var row = i + area.y;
129 for (
int j = 0; j < area.width; j++)
131 var column = j + area.x;
132 var index =
Index(row, column, textureWidth);
144 public static void TileImage(Texture2D texture, Texture2D brush)
149 var brushPixels = brush.GetRawTextureData<Color32>();
150 var pixels = texture.GetRawTextureData<Color32>();
151 var textureHeight = texture.height;
152 var textureWidth = texture.width;
153 var brushHeight = brush.height;
154 var brushWidth = brush.width;
156 for (
int i = 0; i < textureHeight; i++)
160 for (
int j = 0; j < textureWidth; j++)
162 var index =
Index(i, j, textureWidth);
163 var color = brushPixels[
Index(row, column, brushWidth)];
166 if (++column >= brushWidth)
170 if (++row >= brushHeight)
182 public static void DrawImage(Texture2D texture, Texture2D brush, Vector2Int point)
186 var pixels = texture.GetRawTextureData<Color32>();
187 var brushPixels = brush.GetRawTextureData<Color32>();
188 var textureWidth = texture.width;
189 var brushWidth = brush.width;
190 var brushHeight = brush.height;
192 for (
int i = 0; i < brushHeight; i++)
194 var row = i + point.y;
196 for (
int j = 0; j < brushWidth; j++)
198 var column = j + point.x;
199 var index =
Index(row, column, textureWidth);
200 var color = brushPixels[
Index(i, j, brushWidth)];
215 switch (extension.TrimStart(
'.').ToLower())
218 return texture.EncodeToPNG();
221 return texture.EncodeToJPG();
223 throw new ArgumentException($
"Unhandled file extension: {extension}");
233 return texture ==
null || texture.width == 0 || texture.height == 0;
Contains methods for manipulating colors.
static Color CompositeColors(Color colorA, Color colorB)
Calculates the composite of top color A onto bottom color B.
Contains methods for manipulating textures.
static int Index(int row, int column, int columns)
Returns the flat array index corresponding to the row-column index.
static void Fill(Texture2D texture, Color32 color)
Fills the texture with the specified color.
static void TileImage(Texture2D texture, Texture2D brush)
Tiles the image across the texture.
static void FillBorder(Texture2D texture)
Fills the 1 pixel border around the texture with the colors at a 1 pixel inset.
static void CompositeFill(Texture2D texture, Color color, RectInt area)
Composites the color onto the pixels in the specified texture area.
static bool TextureIsNullOrEmpty(Texture2D texture)
Returns true if the texture is null or an empty array.
static byte[] EncodeToBytes(Texture2D texture, string extension)
Returns the image format bytes for the texture corresponding to the file extension (....
static void Fill(Texture2D texture, Color32 color, RectInt area)
Fills the specified texture area with the specified color.
static void DrawImage(Texture2D texture, Texture2D brush, Vector2Int point)
Draws the brush texture at the specified point.
static void CompositeFill(Texture2D texture, Color color)
Composites the color onto all pixels of the specified texture.