/// <summary>
/// Draws gradient rectangle on texture
/// </summary>t
public static void DrawGradientRect(this Texture2D texture, int x, int y, int blockWidth, int blockHeight,
Gradient gradient, Directions progressionDirection)
{
Func<int, int, Color> getColor;
switch (progressionDirection)
{
case Directions.Left:
getColor = (_x, _y) => gradient.Evaluate(1 - (float) _x/(float) blockWidth);
break;
case Directions.Right:
getColor = (_x, _y) => gradient.Evaluate((float) _x/(float) blockWidth);
break;
case Directions.Down:
getColor = (_x, _y) => gradient.Evaluate(1 - (float) _y/(float) blockHeight);
break;
case Directions.Up:
getColor = (_x, _y) => gradient.Evaluate((float) _y/(float) blockHeight);
break;
default:
Debug.LogError("Not supported direction: " + progressionDirection);
return;
}
var colors = new Color[blockWidth*blockHeight];
for (int _y = 0; _y < blockHeight; _y++)
{
for (int _x = 0; _x < blockWidth; _x++)
{
colors[_x + _y*blockWidth] = getColor(_x, _y);
}
}
texture.SetPixels(x, y, blockWidth, blockHeight, colors);
}