Class ColorAssetRegistry
Unified in-memory registry that manages every ColorPaletteAsset
and ColorGradientAsset known to the project. Built-in assets are
discovered automatically via Resources.LoadAll across every module's own
Resources/Color/Palettes and Resources/Color/Gradients folder; user
assets can be registered at runtime via RegisterPalette(ColorPaletteAsset) and
RegisterGradient(ColorGradientAsset). The registry itself is never created as a project
asset (see the "Asset model" remark below).
Inherited Members
Namespace: Scylla.Core.Util.Palette
Assembly: ScyllaCore.dll
Syntax
public sealed class ColorAssetRegistry : ScriptableObject
Remarks
Asset model. This type is intentionally never persisted as a
project asset and has no [ScyllaCreateAsset] entry. The singleton is
constructed in-memory by Instance via
ScriptableObject.CreateInstance, hidden via
HideFlags.HideInHierarchy, dropped on every domain reload and play-mode
entry, and rebuilt fresh on next access. To add a palette or gradient to the
registry, create a ColorPaletteAsset (menu:
Create > Scylla > Core > Color Palette) or
ColorGradientAsset (menu:
Create > Scylla > Core > Color Gradient) and drop it into any
Resources/Color/Palettes/ or Resources/Color/Gradients/ folder
in the project. Discovery picks it up automatically on next registry init.
Transient additions that should not ship as assets can use
RegisterPalette(ColorPaletteAsset) / RegisterGradient(ColorGradientAsset) at runtime.
Why unified? The registry treats every asset equally - palettes and gradients alike are simply named, optionally tagged resources without a built-in / user split. This lets demo / UI / Chroma modules each ship their own assets without Core needing any code-level dependency on them.
Discovery. The first call to Instance issues two
Resources.LoadAll probes: one for palette assets under
PALETTE_RESOURCES_FOLDER and one for gradient assets under
GRADIENT_RESOURCES_FOLDER. Unity merges results across every
Resources/ folder in every assembly, so a module contributes simply by
placing its ColorPaletteAsset / ColorGradientAsset
files in the appropriate Resources subfolder.
Lookups. Every lookup is O(1): an OrdinalIgnoreCase dictionary maps name to asset, and a per-tag dictionary maps tag to a list of assets. Tag membership is case-insensitive at the registry level even though the tag strings on the asset are stored verbatim.
Fallback. If the registry is queried from an unsafe Unity context (ScriptableObject constructor, field initializer, serialization callback) or if no Resources can be loaded, a minimal in-memory fallback is constructed inline (a 2-entry black/white "Empty" palette plus a "Black to White" gradient) so callers still get a usable result for tests and stripped builds. IsFallback indicates the fallback path was taken.
Thread safety. Singleton creation uses a double-checked lock. Runtime registration (RegisterPalette(ColorPaletteAsset), RegisterGradient(ColorGradientAsset), and the matching unregister methods) is not thread-safe - callers must invoke them from the Unity main thread.
Fields
GRADIENT_RESOURCES_FOLDER
Resources subfolder scanned for ColorGradientAsset files. Modules
that ship built-in gradients place them under Resources/Color/Gradients/.
Declaration
public const string GRADIENT_RESOURCES_FOLDER = "Color/Gradients"
Field Value
| Type | Description |
|---|---|
| string |
PALETTE_RESOURCES_FOLDER
Resources subfolder scanned for ColorPaletteAsset files. Modules
that ship built-in palettes place them under Resources/Color/Palettes/
to participate in registry discovery. The shared Resources/Color root is
used by Demos, UI, and Chroma alike.
Declaration
public const string PALETTE_RESOURCES_FOLDER = "Color/Palettes"
Field Value
| Type | Description |
|---|---|
| string |
Properties
AllGradients
Gets a read-only list of every ColorGradient known to the registry.
Declaration
public IReadOnlyList<ColorGradient> AllGradients { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<ColorGradient> |
AllPalettes
Gets a read-only list of every ColorPalette known to the registry.
Declaration
public IReadOnlyList<ColorPalette> AllPalettes { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<ColorPalette> |
GradientCount
The number of gradient entries currently known to the registry. Counts both real assets and overlay-only fallback entries.
Declaration
public int GradientCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
Instance
Gets the singleton registry instance. Constructs it on first access via
UnityEngine.ScriptableObject.CreateInstance<T>() and immediately scans Resources
for built-in palettes and gradients. The instance is never loaded from a project
asset - any .asset file of this type would be ignored by this accessor.
Declaration
public static ColorAssetRegistry Instance { get; }
Property Value
| Type | Description |
|---|---|
| ColorAssetRegistry |
Remarks
Must only be accessed from the Unity main thread because Resources.Load
is not thread-safe.
Access contract. Must not be called from a
UnityEngine.ScriptableObject constructor, field initializer, serialization
callback, or any other context where ScriptableObject.CreateInstance
and Resources.Load are forbidden. Doing so will throw a
UnityEngine.UnityException from Unity itself - the registry no longer
silently substitutes an unsafe-context fallback because that produced a
partially-initialized native object that could crash subsequent Unity API
calls.
IsFallback
true when the registry is using the minimal Core seed because the
Resources/Color/Palettes and Resources/Color/Gradients probes
found no assets. Only the seed "Empty" palette and
"Black to White" gradient are guaranteed in this state. Tests and
editor tooling can poll this flag to detect a freshly-cloned project where
the per-module asset generators haven't been run yet.
Declaration
public bool IsFallback { get; }
Property Value
| Type | Description |
|---|---|
| bool |
PaletteCount
The number of palette entries currently known to the registry. Counts both real assets and overlay-only fallback entries.
Declaration
public int PaletteCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
GetGradient(string)
Gets a gradient by name (case-insensitive). Throws if no match exists.
Declaration
public ColorGradient GetGradient(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The gradient name. Must not be null or empty. |
Returns
| Type | Description |
|---|---|
| ColorGradient | The matching ColorGradient. |
Exceptions
| Type | Condition |
|---|---|
| KeyNotFoundException | If no gradient with the given name is registered. |
GetGradientsByTag(string)
Returns every gradient tagged with the given tag (case-insensitive). Returns an empty list - never null - when no gradients match.
Declaration
public IReadOnlyList<ColorGradient> GetGradientsByTag(string tag)
Parameters
| Type | Name | Description |
|---|---|---|
| string | tag | The tag to match. Null returns an empty list. |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<ColorGradient> | A read-only list of matching gradients in registration order. |
GetPalette(string)
Gets a palette by name (case-insensitive). Throws if no match exists.
Declaration
public ColorPalette GetPalette(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The palette name. Must not be null or empty. |
Returns
| Type | Description |
|---|---|
| ColorPalette | The matching ColorPalette. |
Exceptions
| Type | Condition |
|---|---|
| KeyNotFoundException | If no palette with the given name is registered. |
GetPalettesByTag(string)
Returns every palette tagged with the given tag (case-insensitive). Returns an empty list - never null - when no palettes match.
Declaration
public IReadOnlyList<ColorPalette> GetPalettesByTag(string tag)
Parameters
| Type | Name | Description |
|---|---|---|
| string | tag | The tag to match. Null returns an empty list. |
Returns
| Type | Description |
|---|---|
| IReadOnlyList<ColorPalette> | A read-only list of matching palettes in registration order. |
RegisterGradient(ColorGradientAsset)
Registers a gradient asset at runtime. Duplicate names are rejected.
Declaration
public bool RegisterGradient(ColorGradientAsset asset)
Parameters
| Type | Name | Description |
|---|---|---|
| ColorGradientAsset | asset | The gradient asset to register. Must not be null. |
Returns
| Type | Description |
|---|---|
| bool |
|
RegisterPalette(ColorPaletteAsset)
Registers a palette asset at runtime. The palette becomes available via AllPalettes, GetPalette(string), and any tag listed on the asset's Tags. Duplicate names are rejected.
Declaration
public bool RegisterPalette(ColorPaletteAsset asset)
Parameters
| Type | Name | Description |
|---|---|---|
| ColorPaletteAsset | asset | The palette asset to register. Must not be null. |
Returns
| Type | Description |
|---|---|
| bool |
|
TryGetGradient(string, out ColorGradient)
Tries to get a gradient by name (case-insensitive). The non-throwing alternative to GetGradient(string). Consults the asset map first, then the asset-less overlay (used by the unsafe-context fallback path).
Declaration
public bool TryGetGradient(string name, out ColorGradient gradient)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The gradient name to look up. |
| ColorGradient | gradient | The matching gradient, or |
Returns
| Type | Description |
|---|---|
| bool |
|
TryGetPalette(string, out ColorPalette)
Tries to get a palette by name (case-insensitive). The non-throwing alternative to GetPalette(string). Consults the asset map first, then the asset-less overlay (used by the unsafe-context fallback path).
Declaration
public bool TryGetPalette(string name, out ColorPalette palette)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The palette name to look up. |
| ColorPalette | palette | The matching palette, or |
Returns
| Type | Description |
|---|---|
| bool |
|
UnregisterGradient(ColorGradientAsset)
Unregisters a previously registered gradient asset.
Declaration
public bool UnregisterGradient(ColorGradientAsset asset)
Parameters
| Type | Name | Description |
|---|---|---|
| ColorGradientAsset | asset |
Returns
| Type | Description |
|---|---|
| bool |
UnregisterPalette(ColorPaletteAsset)
Unregisters a previously registered palette asset.
Declaration
public bool UnregisterPalette(ColorPaletteAsset asset)
Parameters
| Type | Name | Description |
|---|---|---|
| ColorPaletteAsset | asset | The palette asset to unregister. |
Returns
| Type | Description |
|---|---|
| bool |
|