> For the complete documentation index, see [llms.txt](https://postica.gitbook.io/coloref/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://postica.gitbook.io/coloref/scripting/cheat-sheet.md).

# API Cheat Sheet

Every ColoRef call you are likely to need, on one page.

Everything is in `using Postica.ColoRef;`.

## Active palette and variation

```csharp
PaletteManager.Active = palette;            // ColoRefAsset; set this at startup in a build
PaletteManager.ActiveVariation = "Night";   // unknown names fall back to the first variation
```

## Reading values

```csharp
Color          c = PaletteManager.GetColor(id, Color.white);
float          f = PaletteManager.GetFloat(id);
int            i = PaletteManager.GetInt(id);
double         d = PaletteManager.GetDouble(id);
bool           b = PaletteManager.GetBool(id);
string         s = PaletteManager.GetString(id);
Gradient       g = PaletteManager.GetGradient(id);   // a copy
AnimationCurve a = PaletteManager.GetCurve(id);      // a copy
Texture2D      t = PaletteManager.GetTexture(id);
Material       m = PaletteManager.GetMaterial(id);
Sprite        sp = PaletteManager.GetSprite(id);
PaletteFont   pf = PaletteManager.GetFont(id);      // pf.font, pf.tmpFont, pf.uitkFont
TextAnchor    ta = PaletteManager.GetTextAlignment(id);
FontStyle     fs = PaletteManager.GetFontStyle(id);
```

Every getter except `GetColor` has an optional fallback as its second argument.

To read from a specific palette and variation instead of the active ones:

```csharp
Color c = palette.GetColor(id, "Night", Color.white);
```

## Finding an id by name

```csharp
string id = palette.variations[0].colors.Find(e => e.name == "Accent")?.id;
string name = palette.GetEntryName(id);
```

## Events

```csharp
PaletteManager.OnActivePaletteChanged   += Refresh;   // a different palette
PaletteManager.OnActiveVariationChanged += Refresh;   // a different variation
PaletteManager.OnColorChanged           += Refresh;   // a value changed (any kind)
```

Unsubscribe in `OnDisable`.

## Editing values

```csharp
var variation = palette.variations.Find(v => v.variationName == "Default");
variation.colors.Find(e => e.name == "Accent").color = Color.red;
palette.NotifyColorChanged();               // linked fields update

var copy = palette.CloneData();             // runtime copy, same ids
```

## Variation Switcher

```csharp
switcher.SwitchTo("Night");
switcher.SwitchToNext();
switcher.SwitchToPrevious();
switcher.SwitchToTarget();
switcher.StopTransition();

switcher.TransitionDuration = 1.5f;
switcher.Scope = PaletteScope.Hierarchy;
bool fading = switcher.IsTransitioning;

switcher.SetBlend("Day", "Night", 0.3f);   // a mix, moved only by calling it again
switcher.EndBlend("Night");
switcher.Show("Dusk");                     // at once, whatever the duration
```

## Overrides

```csharp
PaletteOverrides.Set(id, Color.cyan);       // every kind of entry has a Set
PaletteOverrides.UseEntry(id, otherId);     // read another entry instead
PaletteOverrides.Clear(id);
PaletteOverrides.ClearAll();
using (PaletteOverrides.Batch()) { /* several changes, one update */ }

PaletteOverrides.Save();                    // PlayerPrefs
PaletteOverrides.Load();
string json = PaletteOverrides.ToJson();
```

Play Mode and builds only. See [Overriding Entries at Runtime](/coloref/scripting/overrides.md).

## Player settings

```csharp
var settings = PalettePlayerSettings.Current;
var size = settings.Find("Text Size");
settings.SetNumber(size, 18f);
settings.Select(settings.Find("Theme"), 1);
settings.ResetAll();
settings.Save();
```

## Shader globals

```csharp
palette.shaderGlobals.Add(new ShaderGlobal { entryId = id, propertyName = "_FogTint" });
PaletteShaderGlobals.Apply();
```

## Links

```csharp
PaletteSyncSystem.LinkProperty(light, "color", colorId);
PaletteSyncSystem.LinkProperty(light, "intensity", floatId, valueKind: PaletteValueKind.Float);
PaletteSyncSystem.UnlinkProperty(light, "color");
bool linked = PaletteSyncSystem.IsLinked(light, "color", out string entryId);

PaletteSyncSystem.LinkProperty(renderer, "localMaterial._BaseColor-Color", colorId);   // this renderer only
PaletteSyncSystem.LinkProperty(regions, PaletteTextureRegions.RegionPath(index), colorId);  // a texture region
```

## UI Toolkit

```csharp
element.SetBinding("style.backgroundColor", new PaletteBinding { entryId = colorId });

StyleSheet dark = palette.GetUssStyleSheet("Dark");     // the USS variables of a variation
PaletteUssVariables.Apply(root, palette, "Dark");         // put them on any element
```
