Color
public sealed struct Color Represents a color using 4 floats (rgba), with 0-1 range.
Constructors
Color(Single r, Single g, Single b, Single a) Initialize a color with each component set to given values, in range [0,1]
Color(Single rgb, Single a) Initialize a color with the same value for each color, but a different value for alpha
Color(Single all) Initialize a color with each component set to given value, even alpha.
all — A number in range [0-1] Color(UInt32 raw) Initialize from an integer of the form 0xAABBGGRR.
raw — Packed integer of the form 0xAABBGGRR. Color(Int32 raw) Initialize from an integer of the form 0xAABBGGRR.
raw — Packed integer of the form 0xAABBGGRR. Properties
| Name | Type | Description |
|---|---|---|
Luminance | Single | Returns the luminance of the color, basically it's grayscale value or "black and white version". |
IsRepresentableInHex | Boolean | 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. |
IsSdr | Boolean | Returns true if all components are between 0 and 1 |
IsHdr | Boolean | Returns true if any component exceeds 1 |
Hex | String | String representation of the form "#RRGGBB[AA]". |
Rgba | String | String representation in the form of rgba( r, g, b, a ) css function notation. |
Rgb | String | String representation in the form of rgb( r, g, b ) css function notation. |
RgbaInt | UInt32 | Integer representation of the form 0xRRGGBBAA. |
RgbInt | UInt32 | Integer representation of the form 0xRRGGBB. |
RawInt | UInt32 | Integer representation of the form 0xAABBGGRR as used by native code. |
Random static | Color | Returns a random color out of 8 preset colors. |
Item | Single |
Methods
Color WithAlpha(Single alpha) Returns this color with its alpha value changed
alpha — The required alpha value, usually between 0-1 Color WithAlphaMultiplied(Single alpha) Similar to Single) but multiplies the alpha instead of replacing.
Color WithColorMultiplied(Single amount) Returns a new version with only the red, green, blue components multiplied
Color WithRed(Single red) Returns this color with its red value changed
Color WithGreen(Single green) Returns this color with its green value changed
Color WithBlue(Single blue) Returns this color with its blue value changed
Color32 ToColor32(Boolean srgb = False) Convert to a Color32 (a 32 bit color value)
srgb — If true we'll convert to the srgb color space static Color Min(Color a, Color b) Returns a new color with each component being the minimum of the 2 given colors.
a — Color A b — Color B static Color Max(Color a, Color b) Returns a new color with each component being the maximum of the 2 given colors.
a — Color A b — Color B static Color Average(Color[] values) Returns a color whose components are averaged of all given colors.
values — The colors to get average of. static Color Lerp(Color a, Color b, Single frac, Boolean clamped = True) Performs linear interpolation between two colors.
a — The source color. b — The target color. frac — Fraction to the target color. 0 will return source color, 1 will return target color, 0.5 will "mix" the 2 colors equally. clamped — Clamp fraction to range of [0,1]. If not clamped, the color will be extrapolated. Color LerpTo(Color target, Single frac, Boolean clamp = True) Performs linear interpolation between this and given colors.
target — Color B frac — Fraction, where 0 would return this, 0.5 would return a point between this and given colors, and 1 would return the given color. clamp — Whether to clamp the fraction argument between [0,1] static Color FromBytes(Int32 r, Int32 g, Int32 b, Int32 a = 255) Creates a color from 0-255 range inputs, converting them to 0-1 range.
r — The red component. g — The green component. b — The blue component. a — The alpha/transparency component. static Color FromRgb(UInt32 rgb) Converts an integer of the form 0xRRGGBB into the color #RRGGBB with 100% alpha.
rgb — Integer between 0x000000 and 0xffffff representing a color. static Color FromRgba(UInt32 rgba) Converts an integer of the form 0xRRGGBBAA into the color #RRGGBBAA.
rgba — Integer between 0x00000000 and 0xffffffff representing a color with alpha. Color AdjustHue(Single amount) Increases or decreases this color's hue
amount — A number between -360 and 360 to add to the color's hue Color Darken(Single fraction) Darkens the color by given amount.
fraction — How much to darken the color by, in range of 0 (not at all) to 1 (fully black). Negative values will lighten the color. Color Lighten(Single fraction) Lightens the color by given amount.
fraction — How much to lighten the color by, in range of 0 (not at all) to 1 (double the color). Negative values will darken the color. Color Desaturate(Single fraction) Desaturates the color by given amount.
fraction — How much to desaturate the color by, in range of 0 (not at all) to 1 (no saturation, i.e. fully white). Negative values will saturate the color. Color Saturate(Single fraction) Saturates the color by given amount.
fraction — How much to saturate the color by, in range of 0 (not at all) to 1 (double the saturation). Negative values will desaturate the color. Int32 ComponentCountChangedBetweenColors(Color b) Returns how many color components would be changed between this color and another color
static Color? Parse(String value) Parse the color from a string. Many common formats are supported.
value — The string to parse. static Boolean TryParse(String value, Color color) Try to parse the color. Returns true on success
Fields
| Name | Type | Description |
|---|---|---|
r | Single | The red color component, in range of 0-1, which can be exceeded. |
g | Single | The green color component, in range of 0-1, which can be exceeded. |
b | Single | The blue color component, in range of 0-1, which can be exceeded. |
a | Single | The alpha/transparency color component, in range of 0 (fully transparent) to 1 (fully opaque), which can be exceeded. |
White static | Color | Fully opaque white color. |
Gray static | Color | Fully opaque gray color, right between white and black. |
Black static | Color | Fully opaque black color. |
Red static | Color | Fully opaque pure red color. |
Green static | Color | Fully opaque pure green color. |
Blue static | Color | Fully opaque pure blue color. |
Yellow static | Color | Fully opaque yellow color. |
Orange static | Color | Fully opaque orange color. |
Cyan static | Color | Fully opaque cyan color. |
Magenta static | Color | Fully opaque magenta color. |
Transparent static | Color | Fully transparent color. |
Sandbox.System Full Name: Color