Color
Sandbox.System
Derives from ValueType
Implements IEquatable<Color>

Constructors

Color( float r, float g, float b, float a = 1, )

Initialize a color with each component set to given values, in range [0,1]

Color( float all, )

Initialize a color with each component set to given value, even alpha.

Color( uint raw, )

Initialize from an integer of the form 0xAABBGGRR.

Color( int raw, )

Initialize from an integer of the form 0xAABBGGRR.

Fields

static readonly Color Black

Fully opaque black color.

static readonly Color Blue

Fully opaque pure blue color.

static readonly Color Cyan

Fully opaque cyan color.

static readonly Color Gray

Fully opaque gray color, right between white and black.

static readonly Color Green

Fully opaque pure green color.

static readonly Color Magenta

Fully opaque magenta color.

static readonly Color Orange

Fully opaque orange color.

static readonly Color Red

Fully opaque pure red color.

static readonly Color Transparent

Fully transparent color.

static readonly Color White

Fully opaque white color.

static readonly Color Yellow

Fully opaque yellow color.

float a

The alpha/transparency color component, in range of 0 (fully transparent) to 1 (fully opaque), which can be exceeded.

float b

The blue color component, in range of 0-1, which can be exceeded.

float g

The green color component, in range of 0-1, which can be exceeded.

float r

The red color component, in range of 0-1, which can be exceeded.

Properties

static Color Random { get; }

Returns a random color out of 8 preset colors.

string Hex { get; }

String representation of the form "#RRGGBB[AA]".

bool IsRepresentableInHex { get; }

Returns true if this color can be represented in hexadecimal format (#RRGGBB[AA]). This may not be the case if the color components are outside of [0,1] range.

float Luminance { get; }

Returns the luminance of the color, basically it's grayscale value or "black and white version".

uint RawInt { get; }

Integer representation of the form 0xAABBGGRR as used by native code.

string Rgb { get; }

String representation in the form of rgb( r, g, b ) css function notation.

string Rgba { get; }

String representation in the form of rgba( r, g, b, a ) css function notation.

uint RGBA { get; }
Marked as obsolete: Use RgbaInt, note that the endianness has been reversed
uint RgbaInt { get; }

Integer representation of the form 0xRRGGBBAA.

uint RgbInt { get; }

Integer representation of the form 0xRRGGBB.

Methods

static Color Average( Color[] values, )

Returns a color whose components are averaged of all given colors.

static Color FromBytes( int r, int g, int b, int a = 255, )

Creates a color from 0-255 range inputs, converting them to 0-1 range.

static Color FromRgb( uint rgb, )

Converts an integer of the form 0xRRGGBB into the color #RRGGBB with 100% alpha.

static Color FromRgba( uint rgba, )

Converts an integer of the form 0xRRGGBBAA into the color #RRGGBBAA.

static Color Lerp( Color a, Color b, float frac, bool clamped = true, )

Performs linear interpolation between two colors.

static Color Max( Color a, Color b, )

Returns a new color with each component being the maximum of the 2 given colors.

static Color Min( Color a, Color b, )

Returns a new color with each component being the minimum of the 2 given colors.

static Color? Parse( string value, )

Parse the color from a string. Many common formats are supported.

static Color Read( BinaryReader reader, )

Read a color from binary reader.

Returns how many color components would be changed between this color and another color

Color Darken( float fraction, )

Darkens the color by given amount.

Color Desaturate( float fraction, )

Desaturates the color by given amount.

Returns inverted color. Alpha is unchanged.

Color Lighten( float fraction, )

Lightens the color by given amount.

Color Saturate( float fraction, )

Saturates the color by given amount.

Color32 ToColor32( bool srgb = false, )

Convert to a Color32 (a 32 bit color value)

Converts this color to a HSV format.

string ToString( bool hex, bool rgba, )

Converts the color to a string with given parameters.

Color WithAlpha( float alpha, )

Returns this color with its alpha value changed

Color WithAlphaMultiplied( float alpha, )

Similar to Color.WithAlpha but multiplies the alpha instead of replacing.

Color WithBlue( float blue, )

Returns this color with its blue value changed

Color WithGreen( float green, )

Returns this color with its green value changed

Color WithRed( float red, )

Returns this color with its red value changed

void Write( BinaryWriter writer, )

Write this color to a binary writer.

override bool Equals( object obj, )
Overrides ValueType.Equals
override bool Equals( Color o, )
Overrides ValueType.Equals
override int GetHashCode( )
Overrides ValueType.GetHashCode
override string ToString( )
Overrides ValueType.ToString

Operators

float this[ int index,  ]

Get color components by numerical index.

Color +( Color c1, Color c2,  )
bool ==( Color left, Color right,  )
bool !=( Color left, Color right,  )
Color *( Color c1, float f,  )

Multiply each component of this color by given value.

Color -( Color c1, Color c2,  )
implicit Color =( Vector4 value,  )
implicit Color =( Vector3 value,  )
implicit Color =( Color32 color,  )
implicit Color =( string value,  )