# Color

Kind: Struct · Namespace: Sansar · Assembly: Sansar.Script.dll · Script API 47.10.0

<div class="api-meta">
<span class="api-kind api-kind-struct" data-pagefind-filter="kind:Struct">Struct</span>
<span data-pagefind-filter="namespace:Sansar">Namespace <a href="/scripting/api/sansar"><code>Sansar</code></a></span>
</div>

<span id="T:Sansar.Color"></span>

The Color class holds RGBA values that define a color.

```csharp
public struct Color
```

## Members at a glance

| Kind | Members |
|---|---|
| **Constructors** | [Color](#color) |
| **Fields** | [Black](#black) · [Blue](#blue) · [Clear](#clear) · [Cyan](#cyan) · [Gray](#gray) · [Green](#green) · [Magenta](#magenta) · [Red](#red) · [White](#white) · [Yellow](#yellow) |
| **Properties** | [A](#a) · [B](#b) · [G](#g) · [R](#r) |
| **Methods** | [Lerp](#lerp) · [Parse](#parse) · [ToRGB](#torgb) · [ToRGBA](#torgba) · [ToString](#tostring) · [TryParse](#tryparse) |
| **Operators** | [op\_Addition](#op_addition) · [op\_Division](#op_division) · [op\_Implicit](#op_implicit) · [op\_Multiply](#op_multiply) · [op\_Subtraction](#op_subtraction) |

## Constructors

### Color

<div class="api-card" id="ctor-vector4f">
<span id="M:Sansar.Color.#ctor(Mono.Simd.Vector4f)"></span>
<span id="C:Sansar.Color(Mono.Simd.Vector4f)"></span>

```csharp signature
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`. |

</div>

<div class="api-card" id="ctor-single-single-single">
<span id="M:Sansar.Color.#ctor(System.Single,System.Single,System.Single)"></span>
<span id="C:Sansar.Color(System.Single,System.Single,System.Single)"></span>

```csharp signature
public Color(float r, float g, float b)
```

Creates a new solid color with the supplied values.

| Parameter | Type | Description |
|---|---|---|
| `r` | [float](https://learn.microsoft.com/dotnet/api/system.single) | The red component. |
| `g` | [float](https://learn.microsoft.com/dotnet/api/system.single) | The green component. |
| `b` | [float](https://learn.microsoft.com/dotnet/api/system.single) | The blue component. |

<details class="api-remarks"><summary>Remarks</summary>

The alpha component is set to 1.

</details>

</div>

<div class="api-card" id="ctor-single-single-single-single">
<span id="M:Sansar.Color.#ctor(System.Single,System.Single,System.Single,System.Single)"></span>
<span id="C:Sansar.Color(System.Single,System.Single,System.Single,System.Single)"></span>

```csharp signature
public Color(float r, float g, float b, float a)
```

Creates a new color with the supplied values.

| Parameter | Type | Description |
|---|---|---|
| `r` | [float](https://learn.microsoft.com/dotnet/api/system.single) | The red component. |
| `g` | [float](https://learn.microsoft.com/dotnet/api/system.single) | The green component. |
| `b` | [float](https://learn.microsoft.com/dotnet/api/system.single) | The blue component. |
| `a` | [float](https://learn.microsoft.com/dotnet/api/system.single) | The alpha component. |

</div>


## Fields

### Black

<div class="api-card">
<span id="F:Sansar.Color.Black"></span>

```csharp signature
public static readonly Color Black
```

Black

</div>

### Blue

<div class="api-card">
<span id="F:Sansar.Color.Blue"></span>

```csharp signature
public static readonly Color Blue
```

Blue

</div>

### Clear

<div class="api-card">
<span id="F:Sansar.Color.Clear"></span>

```csharp signature
public static readonly Color Clear
```

Clear

</div>

### Cyan

<div class="api-card">
<span id="F:Sansar.Color.Cyan"></span>

```csharp signature
public static readonly Color Cyan
```

Cyan

</div>

### Gray

<div class="api-card">
<span id="F:Sansar.Color.Gray"></span>

```csharp signature
public static readonly Color Gray
```

Gray

</div>

### Green

<div class="api-card">
<span id="F:Sansar.Color.Green"></span>

```csharp signature
public static readonly Color Green
```

Green

</div>

### Magenta

<div class="api-card">
<span id="F:Sansar.Color.Magenta"></span>

```csharp signature
public static readonly Color Magenta
```

Magenta

</div>

### Red

<div class="api-card">
<span id="F:Sansar.Color.Red"></span>

```csharp signature
public static readonly Color Red
```

Red

</div>

### White

<div class="api-card">
<span id="F:Sansar.Color.White"></span>

```csharp signature
public static readonly Color White
```

White

</div>

### Yellow

<div class="api-card">
<span id="F:Sansar.Color.Yellow"></span>

```csharp signature
public static readonly Color Yellow
```

Yellow

</div>


## Properties

### A

<div class="api-card">
<span id="P:Sansar.Color.A"></span>

```csharp signature
public float A { get; set; }
```

The alpha component of the color.

<details class="api-remarks"><summary>Remarks</summary>

Alpha is 1 by default.

</details>

</div>

### B

<div class="api-card">
<span id="P:Sansar.Color.B"></span>

```csharp signature
public float B { get; set; }
```

The blue component of the color.

</div>

### G

<div class="api-card">
<span id="P:Sansar.Color.G"></span>

```csharp signature
public float G { get; set; }
```

The green component of the color.

</div>

### R

<div class="api-card">
<span id="P:Sansar.Color.R"></span>

```csharp signature
public float R { get; set; }
```

The red component of the color.

</div>


## Methods

### Lerp

<div class="api-card">
<span id="M:Sansar.Color.Lerp(Sansar.Color@,System.Single)"></span>

```csharp signature
public Color Lerp(ref Color c, float amount)
```

Performs a linear interpolation between two colors.

| Parameter | Type | Description |
|---|---|---|
| `c` | [Color](/scripting/api/sansar/color) | The second color. |
| `amount` | [float](https://learn.microsoft.com/dotnet/api/system.single) | Value from \[0..1\] indicating the weight for the second color. |

**Returns:** [Color](/scripting/api/sansar/color) — A color that is linearly interpolated between the two sources.

<details class="api-remarks"><summary>Remarks</summary>

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.

</details>

</div>

### Parse

<div class="api-card">
<span id="M:Sansar.Color.Parse(System.String)"></span>

```csharp signature
public static Color Parse(string colorString)
```

Parse a Color from a string.

| Parameter | Type | Description |
|---|---|---|
| `colorString` | [string](https://learn.microsoft.com/dotnet/api/system.string) | A string of the format (R,G,B) or (R,G,B,A) |

**Returns:** [Color](/scripting/api/sansar/color) — The Color parsed from the string.

**Throws** [`ArgumentException`](https://learn.microsoft.com/dotnet/api/system.argumentexception): If colorString is null.

**Throws** [`FormatException`](https://learn.microsoft.com/dotnet/api/system.formatexception): If the string is not a valid color or its components are not valid floats.

<details class="api-example" open><summary>Example</summary>

```csharp
Color myColor = Color.Parse("(0.5,1.0,0.8)");
```

</details>

</div>

### ToRGB

<div class="api-card">
<span id="M:Sansar.Color.ToRGB"></span>
<span id="M:Sansar.Color.ToRGB()"></span>

```csharp signature
public string ToRGB()
```

Generates a string RGB representation of the color.

**Returns:** [string](https://learn.microsoft.com/dotnet/api/system.string) — The RGB color as a string.

<details class="api-remarks"><summary>Remarks</summary>

RGB values are based on a scale from 0 to 255.

</details>

</div>

### ToRGBA

<div class="api-card">
<span id="M:Sansar.Color.ToRGBA"></span>
<span id="M:Sansar.Color.ToRGBA()"></span>

```csharp signature
public string ToRGBA()
```

Generates a string RGBA representation of the color.

**Returns:** [string](https://learn.microsoft.com/dotnet/api/system.string) — The RGBA color as a string.

</div>

### ToString

<div class="api-card" id="tostring-noargs">
<span id="M:Sansar.Color.ToString"></span>
<span id="M:Sansar.Color.ToString()"></span>

```csharp signature
public override string ToString()
```

Generates a string representation of the color.

**Returns:** [string](https://learn.microsoft.com/dotnet/api/system.string) — The color as a string.

</div>

<div class="api-card" id="tostring-string">
<span id="M:Sansar.Color.ToString(System.String)"></span>

```csharp signature
public string ToString(string format)
```

Generates a string representation of the color.

| Parameter | Type | Description |
|---|---|---|
| `format` | [string](https://learn.microsoft.com/dotnet/api/system.string) | Format to use for each of the coordinates. |

**Returns:** [string](https://learn.microsoft.com/dotnet/api/system.string) — The color as a string.

</div>

### TryParse

<div class="api-card">
<span id="M:Sansar.Color.TryParse(System.String,Sansar.Color@)"></span>

```csharp signature
public static bool TryParse(string colorString, out Color color)
```

Attempt to parse a Color from a string

| Parameter | Type | Description |
|---|---|---|
| `colorString` | [string](https://learn.microsoft.com/dotnet/api/system.string) | A string of the format (R,G,B) or (R,G,B,A) |
| `color` | [Color](/scripting/api/sansar/color) | The color that will be set if colorString represents a valid color. |

**Returns:** [bool](https://learn.microsoft.com/dotnet/api/system.boolean) — True if successfully parsed a color, false if not.

<details class="api-example" open><summary>Example</summary>

```csharp
Color myColor;
if (Color.Parse("(0.5,1.0,0.8)", out myColor)
{
    // myColor is set
}
```

</details>

</div>


## Operators

### op_Addition

<div class="api-card">
<span id="M:Sansar.Color.op_Addition(Sansar.Color,Sansar.Color)"></span>

```csharp signature
public static Color operator +(Color a, Color b)
```

Performs color addition.

| Parameter | Type | Description |
|---|---|---|
| `a` | [Color](/scripting/api/sansar/color) | The first Color. |
| `b` | [Color](/scripting/api/sansar/color) | The second Color. |

**Returns:** [Color](/scripting/api/sansar/color) — A new color that is the sum of the arguments.

</div>

### op_Division

<div class="api-card">
<span id="M:Sansar.Color.op_Division(Sansar.Color,System.Single)"></span>

```csharp signature
public static Color operator /(Color c, float s)
```

Divides color components by a scalar.

| Parameter | Type | Description |
|---|---|---|
| `c` | [Color](/scripting/api/sansar/color) | The color. |
| `s` | [float](https://learn.microsoft.com/dotnet/api/system.single) | The scalar. |

**Returns:** [Color](/scripting/api/sansar/color) — Returns a new color with value \[c.R/s, c.G/s, c.B/s, c.A/s\]

</div>

### op_Implicit

<div class="api-card" id="opimplicit-color">
<span id="M:Sansar.Color.op_Implicit(Mono.Simd.Vector4f)~Sansar.Color"></span>

```csharp signature
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 |

</div>

<div class="api-card" id="opimplicit-vector4f">
<span id="M:Sansar.Color.op_Implicit(Sansar.Color)~Mono.Simd.Vector4f"></span>

```csharp signature
public static implicit operator Mono.Simd.Vector4f(Color c)
```

Converts a Color to a Mono.Simd.Vector4f

| Parameter | Type | Description |
|---|---|---|
| `c` | [Color](/scripting/api/sansar/color) | Color to convert |

</div>

### op_Multiply

<div class="api-card" id="opmultiply-color-single">
<span id="M:Sansar.Color.op_Multiply(Sansar.Color,System.Single)"></span>

```csharp signature
public static Color operator *(Color c, float s)
```

Performs a color scalar multiplication.

| Parameter | Type | Description |
|---|---|---|
| `c` | [Color](/scripting/api/sansar/color) | The color. |
| `s` | [float](https://learn.microsoft.com/dotnet/api/system.single) | The scalar. |

**Returns:** [Color](/scripting/api/sansar/color) — Returns a new color with value \[c.R\*s, c.G\*s, c.B\*s, c.A\*s\]

</div>

<div class="api-card" id="opmultiply-single-color">
<span id="M:Sansar.Color.op_Multiply(System.Single,Sansar.Color)"></span>

```csharp signature
public static Color operator *(float s, Color c)
```

Performs a color scalar multiplication.

| Parameter | Type | Description |
|---|---|---|
| `s` | [float](https://learn.microsoft.com/dotnet/api/system.single) | The scalar. |
| `c` | [Color](/scripting/api/sansar/color) | The color. |

**Returns:** [Color](/scripting/api/sansar/color) — Returns a new color with value \[s\*c.R, s\*c.G, s\*c.B, s\*c.A\]

</div>

### op_Subtraction

<div class="api-card">
<span id="M:Sansar.Color.op_Subtraction(Sansar.Color,Sansar.Color)"></span>

```csharp signature
public static Color operator -(Color a, Color b)
```

Performs color subtraction.

| Parameter | Type | Description |
|---|---|---|
| `a` | [Color](/scripting/api/sansar/color) | The first Color. |
| `b` | [Color](/scripting/api/sansar/color) | The second Color. |

**Returns:** [Color](/scripting/api/sansar/color) — A new color that is the difference of the arguments.

</div>


## Used in examples

- [ScriptLibrary/Quest/QuestObjectBase.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Quest/QuestObjectBase.cs)
- [ScriptLibrary/Scene/Light.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Scene/Light.cs)
- [ScriptLibrary/Scene/LightOnOff.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Scene/LightOnOff.cs)
- [ScriptLibrary/Scene/ProgressBar.cs](https://github.com/Wookey-Technologies/sansar-script-starter/blob/66af8b516b701088d043e4615acfcf5779356604/examples/official/ScriptLibrary/Scene/ProgressBar.cs)

<p class="api-generated" data-pagefind-ignore>Generated from the Sansar 47.10.0 client ScriptApi snapshot.</p>