Skip to content

ColorUtility

Namespace: SideXP.Core

public static class ColorUtility

Miscellaneous functions for working with Color and Color32 values.

Fields

MaxColorValue

public const int MaxColorValue = 255

The maximum color value.

MaxColorValueFloat

public const float MaxColorValueFloat = 255

The maximum color value as float.

Methods

ToHexRGB(Color)

public static string ToHexRGB(Color color)

Converts the given color into an hexadecimal string value.

Parameters

  • color: The color to convert.

Returns

Returns the "color string" with format "RRGGBB".

ToHexRGB(Color32)

public static string ToHexRGB(Color32 color)

Converts the given color into an hexadecimal string value.

Parameters

  • color: The color to convert.

Returns

Returns the "color string" with format "RRGGBB".

ToHexRGBA(Color)

public static string ToHexRGBA(Color color)

Converts the given color into an hexadecimal string value.

Parameters

  • color: The color to convert.

Returns

Returns the "color string" with format "RRGGBBAA".

ToHexRGBA(Color32)

public static string ToHexRGBA(Color32 color)

Returns

Returns the "color string" with format "RRGGBBAA".

FromHex(Color, string)

public static bool FromHex(ref Color color, string hexString)

Sets the given color values from the given hexadecimal string.

Parameters

  • color: The color to override.
  • hexString: The hexadecimal string: - #RGB (becomes RRGGBB) - #RRGGBB - #RGBA (becomes RRGGBBAA) - #RRGGBBAA

Returns

Returns true if the string has been parsed successfully.

FromHex(string)

public static Color FromHex(string hexString)

Creates a color value from the given hexadecimal string.

Parameters

  • hexString: The hexadecimal string: - #RGB (becomes RRGGBB) - #RRGGBB - #RGBA (becomes RRGGBBAA) - #RRGGBBAA

Returns

Returns the created color value.

FromHex32(Color32, string)

public static bool FromHex32(ref Color32 color, string hexString)

Sets the given color values from the given hexadecimal string.

Parameters

  • color: The color to override.
  • hexString: The hexadecimal string: - #RGB (becomes RRGGBB) - #RRGGBB - #RGBA (becomes RRGGBBAA) - #RRGGBBAA

Returns

Returns true if the string has been parsed successfully.

FromHex32(string)

public static Color32 FromHex32(string hexString)

Inherited documentation.

GenerateRandomColor(int)

public static Color GenerateRandomColor(int subdivs = 4)

Generates a random color.

Parameters

  • subdivs: The number of subdivs a single color channel can have when generating random color. As an example, if you set 2, a channel can get value 0, 0.5 or 1. Values below 1 are clamped to 1 (a channel then gets only 0 or 1).

Returns

Returns the generated color.

GetOverlayTint(Color)

public static Color GetOverlayTint(Color color)

Gets the appropriate tint to make the content over the given color as visible as possible.

Parameters

  • color: The color to process.

Returns

Returns black if the grayscale of the given color is over 0.5, otherwise white.

GetOverlayTint(Color32)

public static Color32 GetOverlayTint(Color32 color)

Gets the appropriate tint to make the content over the given color as visible as possible.

Parameters

  • color: The color to process.

Returns

Returns black if the grayscale of the given color is over 0.5, otherwise white.