The Color class holds RGBA values that define a color.
public struct ColorMembers at a glance
| Kind | Members |
|---|---|
| Constructors | Color |
| Fields | Black · Blue · Clear · Cyan · Gray · Green · Magenta · Red · White · Yellow |
| Properties | A · B · G · R |
| Methods | Lerp · Parse · ToRGB · ToRGBA · ToString · TryParse |
| Operators | op_Addition · op_Division · op_Implicit · op_Multiply · op_Subtraction |
Constructors
Color
public Color(Mono.Simd.Vector4f v)Creates a new color with the supplied values.
| Parameter | Type | Description |
|---|---|---|
v | Mono.Simd.Vector4f | Initializes the color from a Vector4f. |
public Color(float r, float g, float b)Creates a new solid color with the supplied values.
| Parameter | Type | Description |
|---|---|---|
r | float | The red component. |
g | float | The green component. |
b | float | The blue component. |
Remarks
The alpha component is set to 1.
public Color(float r, float g, float b, float a)Creates a new color with the supplied values.
| Parameter | Type | Description |
|---|---|---|
r | float | The red component. |
g | float | The green component. |
b | float | The blue component. |
a | float | The alpha component. |
Fields
Black
public static readonly Color BlackBlack
Blue
public static readonly Color BlueBlue
Clear
public static readonly Color ClearClear
Cyan
public static readonly Color CyanCyan
Gray
public static readonly Color GrayGray
Green
public static readonly Color GreenGreen
Magenta
public static readonly Color MagentaMagenta
Red
public static readonly Color RedRed
White
public static readonly Color WhiteWhite
Yellow
public static readonly Color YellowYellow
Properties
A
public float A { get; set; }The alpha component of the color.
Remarks
Alpha is 1 by default.
B
public float B { get; set; }The blue component of the color.
G
public float G { get; set; }The green component of the color.
R
public float R { get; set; }The red component of the color.
Methods
Lerp
public Color Lerp(ref Color c, float amount)Performs a linear interpolation between two colors.
| Parameter | Type | Description |
|---|---|---|
c | Color | The second color. |
amount | float | Value from [0..1] indicating the weight for the second color. |
Returns: Color — A color that is linearly interpolated between the two sources.
Remarks
This method performs the linear interpolation as:
a + (c-a) * amount.
An amount value of 0 returns the original color, and 1.0 returns color c.
Parse
public static Color Parse(string colorString)Parse a Color from a string.
| Parameter | Type | Description |
|---|---|---|
colorString | string | A string of the format (R,G,B) or (R,G,B,A) |
Returns: Color — The Color parsed from the string.
Throws ArgumentException: If colorString is null.
Throws FormatException: If the string is not a valid color or its components are not valid floats.
Example
Color myColor = Color.Parse("(0.5,1.0,0.8)");ToRGB
public string ToRGB()Generates a string RGB representation of the color.
Returns: string — The RGB color as a string.
Remarks
RGB values are based on a scale from 0 to 255.
ToRGBA
public string ToRGBA()Generates a string RGBA representation of the color.
Returns: string — The RGBA color as a string.
ToString
public override string ToString()Generates a string representation of the color.
Returns: string — The color as a string.
public string ToString(string format)Generates a string representation of the color.
| Parameter | Type | Description |
|---|---|---|
format | string | Format to use for each of the coordinates. |
Returns: string — The color as a string.
TryParse
public static bool TryParse(string colorString, out Color color)Attempt to parse a Color from a string
| Parameter | Type | Description |
|---|---|---|
colorString | string | A string of the format (R,G,B) or (R,G,B,A) |
color | Color | The color that will be set if colorString represents a valid color. |
Returns: bool — True if successfully parsed a color, false if not.
Example
Color myColor;if (Color.Parse("(0.5,1.0,0.8)", out myColor){ // myColor is set}Operators
op_Addition
public static Color operator +(Color a, Color b)Performs color addition.
| Parameter | Type | Description |
|---|---|---|
a | Color | The first Color. |
b | Color | The second Color. |
Returns: Color — A new color that is the sum of the arguments.
op_Division
public static Color operator /(Color c, float s)Divides color components by a scalar.
| Parameter | Type | Description |
|---|---|---|
c | Color | The color. |
s | float | The scalar. |
Returns: Color — Returns a new color with value [c.R/s, c.G/s, c.B/s, c.A/s]
op_Implicit
public static implicit operator Color(Mono.Simd.Vector4f v)Converts a Mono.Simd.Vector4f to a Color.
| Parameter | Type | Description |
|---|---|---|
v | Mono.Simd.Vector4f | Vector to convert |
public static implicit operator Mono.Simd.Vector4f(Color c)Converts a Color to a Mono.Simd.Vector4f
| Parameter | Type | Description |
|---|---|---|
c | Color | Color to convert |
op_Multiply
public static Color operator *(Color c, float s)Performs a color scalar multiplication.
| Parameter | Type | Description |
|---|---|---|
c | Color | The color. |
s | float | The scalar. |
Returns: Color — Returns a new color with value [c.R*s, c.G*s, c.B*s, c.A*s]
public static Color operator *(float s, Color c)Performs a color scalar multiplication.
| Parameter | Type | Description |
|---|---|---|
s | float | The scalar. |
c | Color | The color. |
Returns: Color — Returns a new color with value [s*c.R, s*c.G, s*c.B, s*c.A]
op_Subtraction
public static Color operator -(Color a, Color b)Performs color subtraction.
| Parameter | Type | Description |
|---|---|---|
a | Color | The first Color. |
b | Color | The second Color. |
Returns: Color — A new color that is the difference of the arguments.
Used in examples
- ScriptLibrary/Quest/QuestObjectBase.cs
- ScriptLibrary/Scene/Light.cs
- ScriptLibrary/Scene/LightOnOff.cs
- ScriptLibrary/Scene/ProgressBar.cs
Generated from the Sansar 47.10.0 client ScriptApi snapshot.