Class ColorPaletteMapping
A cached mapping from one ColorPalette to another, computed using a three-step fallback resolution chain: ID match, role match, perceptual nearest. Once created, the mapping can resolve colors repeatedly without recomputing.
Inherited Members
Namespace: Scylla.Core.Util.Palette
Assembly: ScyllaCore.dll
Syntax
public sealed class ColorPaletteMapping
Remarks
Resolution chain. For each entry in the source palette, the mapping finds the best match in the target palette using this priority order:
- ID match (case-insensitive) -- if the target palette has an entry with the same ID, use it.
- Role match -- if the source entry has a non-None ColorRole, find the first entry in the target with the same role.
- Perceptual nearest -- find the visually closest color in the target using the redmean weighted RGB distance algorithm.
Caching. The mapping is computed once at construction and stored as an integer index array. Subsequent Resolve(int) and Resolve(string) calls are O(1) lookups. Cache a mapping instance when switching between the same palette pair frequently (e.g., toggling Light/Dark themes).
Immutability. Like ColorPalette itself, a mapping is immutable after construction. If either palette changes, create a new mapping.
Constructors
ColorPaletteMapping(ColorPalette, ColorPalette)
Creates a new mapping from source to target palette using the three-step fallback resolution chain.
Declaration
public ColorPaletteMapping(ColorPalette source, ColorPalette target)
Parameters
| Type | Name | Description |
|---|---|---|
| ColorPalette | source | The palette to map from. Must not be null. |
| ColorPalette | target | The palette to map to. Must not be null. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If source or target is null. |
Properties
Source
The source palette this mapping was created from.
Declaration
public ColorPalette Source { get; }
Property Value
| Type | Description |
|---|---|
| ColorPalette | The ColorPalette supplied as the |
Target
The target palette this mapping resolves to.
Declaration
public ColorPalette Target { get; }
Property Value
| Type | Description |
|---|---|
| ColorPalette | The ColorPalette supplied as the |
Methods
GetTargetIndex(int)
Gets the target palette index that a source index maps to.
Declaration
public int GetTargetIndex(int sourceIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | sourceIndex | Zero-based index in the source palette. |
Returns
| Type | Description |
|---|---|
| int | The zero-based index in the target palette. |
Exceptions
| Type | Condition |
|---|---|
| IndexOutOfRangeException | If sourceIndex is out of range. |
Resolve(int)
Resolves a source palette index to the corresponding target color (float precision).
Declaration
public Color Resolve(int sourceIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | sourceIndex | Zero-based index in the source palette. |
Returns
| Type | Description |
|---|---|
| Color | The resolved UnityEngine.Color from the target palette. |
Exceptions
| Type | Condition |
|---|---|
| IndexOutOfRangeException | If sourceIndex is out of range. |
Resolve(string)
Resolves a color from the source palette, identified by its ID, to the target palette.
Declaration
public Color Resolve(string sourceID)
Parameters
| Type | Name | Description |
|---|---|---|
| string | sourceID | The color ID in the source palette (case-insensitive). Must exist in source. |
Returns
| Type | Description |
|---|---|
| Color | The resolved UnityEngine.Color from the target palette. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If sourceID is null. |
| ArgumentException | If sourceID is not found in the source palette. |
Resolve32(int)
Resolves a source palette index to the corresponding target color (byte precision).
Declaration
public Color32 Resolve32(int sourceIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | sourceIndex | Zero-based index in the source palette. |
Returns
| Type | Description |
|---|---|
| Color32 | The resolved UnityEngine.Color32 from the target palette. |
Exceptions
| Type | Condition |
|---|---|
| IndexOutOfRangeException | If sourceIndex is out of range. |
ToString()
Returns a human-readable string: "Source -> Target (N entries)".
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |