The FillRectangle helper methods allow you to draw a filled rectangles inside OnGUI methods.
/// <summary>
/// Draws a filled rectangle.
/// </summary>
/// <param name="rect">
/// A <see cref="Rect"/> type that defines the bounds of the rectangle to draw.
/// </param>
public static void FillRectangle(Rect rect)
{
FillRectangle(rect, GUI.color);
}
/// <summary>
/// Draws a filled rectangle.
/// </summary>
/// <param name="rect">
/// A <see cref="Rect"/> type that defines the bounds of the rectangle to draw.
/// </param>
/// <param name="color">
/// The color of the rectangle.
/// </param>
public static void FillRectangle(Rect rect, Color color)
{
// Store current GUI color, so we can switch it back later,
// and set the GUI color to the color parameter
var savedColor = GUI.color;
GUI.color = color;
// Finally, draw the actual rectangle.
GUI.DrawTexture(rect, Texture2D.whiteTexture, ScaleMode.StretchToFill);
// We're done. Restore the GUI matrix and GUI color to whatever they were before.
GUI.color = savedColor;
}