Assets/_Molca/_Core/ColorID/Namespace:
Molca.ColorID
Central swatch + color id theming for Unity UI and renderers. Data lives in a ColorModule asset registered on Global Settings. Optional ColorSchemeManager subsystem swaps whole ColorModule instances (e.g. light/dark).
ColorModule (SettingModule)
File: ColorModule.csCreate asset: Molca → Settings → Color Settings
- Swatches — named groups (e.g.
Default) each holdingcolorId→ Color definitions. Cache keys areSwatchName.ColorIdinternally. - Runtime API —
ColorModule.GetColor(swatchName, colorId),GetColor(colorId)(default swatch / search),HasColor,GetAllColorIds,SetActiveModule(used when switching schemes). - Persistence — per-color overrides can be stored in PlayerPrefs via module save/load paths (see source for
UpdateColor/GetColorWithFallback).
GlobalSettings module list like other setting modules.
ColorID component
File:ColorID.csAdd component: Molca → Utilities → Color ID
- Swatch name + color id select which entry from the active
ColorModuleto apply. - Targets — list of
ColorTargetentries (type: Auto, Renderer, Image, TMP, etc.). If the list is empty at runtime, the component can auto-discover renderers/UI on this object (and optionally children viaapplyToChildren). - After
RuntimeManager.WaitForInitialization(), subscribes toColorSchemeManager.OnSchemeChangedand reapplies colors. SetColor(swatchName, colorId)/SetColorId(...)—SetColorIdsupports composite"SwatchName/colorId"(note:ColorModulecache uses dotSwatchName.ColorId; the component’s composite split uses slash for the two-field API only).
Renderers in the Editor
Renderer color application runs in play mode only (see source) so shared materials are not mutated in edit mode.
ColorSchemeManager (RuntimeSubsystem)
File: ColorSchemeManager.cs
Child on the RuntimeManager prefab alongside other subsystems. Holds an array of ColorModule assets and activates one at init ( PlayerPrefs key ColorScheme_Active).
API: ColorSchemeManager.SetScheme(index | name, save), ToggleScheme, PreviousScheme, RefreshAllColorIDs. Changing scheme calls ColorModule.SetActiveModule and raises OnSchemeChanged.
ColorIDReference (serialized field)
File:ColorIDReference.cs
Serializable swatch + id pair with Color, GetColorWithAlpha, IsValid(), implicit conversions from string and to Color. Use on your own MonoBehaviour when you assign colors in code rather than using the ColorID driver component.
SDK example: ColorID/Examples/ColorIDReferenceExample.cs.
ColorUtility
File:ColorUtility.cs
Static helpers: ApplyColorToGameObject (adds/configures ColorID), ApplyColorToComponent, CreateColorID, RefreshColorIDs, LerpColor, etc.
Editor menu (ColorModule)
FromColorModule (editor section):
- Molca → ColorID → Apply Colors to all IDs — refresh all
ColorIDinstances in the open scene(s). - Molca → ColorID → Scan and select invalid IDs — select objects whose swatch/id is missing from the cache.
Code
Resolve a color after startup:Troubleshooting
- Color stays wrong or never updates — Confirm
RuntimeManager.WaitForInitialization()has completed before readingColorIDReference.Coloror callingColorSchemeManager.SetScheme. Ensure aColorModuleis registered on Global Settings andColorSchemeManageris present on the RuntimeManager prefab if you rely on scheme switching. - Swatch/id exists in the asset but resolves incorrectly at runtime — Remember
ColorModulecache keys useSwatchName.ColorId(dot).ColorID.SetColorIdaccepts a compositeSwatchName/colorId(slash) for the two-part overload only; mismatched strings or typos show up as missing entries in Scan and select invalid IDs. - UI updates but meshes/renderers do not in the Editor —
Renderertargets apply in play mode only by design so shared materials are not edited in the Inspector; enter Play Mode or use UI/Image/TMP targets for edit-time previews where supported. SetSchemehas no visible effect — Check theColorSchemeManagermodule list andPlayerPrefskeyColorScheme_Active; callRefreshAllColorIDsafter bulk changes. EnsureColorIDcomponents subscribe after init (they listen forOnSchemeChanged).- Invalid ID scan finds false positives — Active module vs asset mismatch (wrong
ColorModuleon Global Settings) or stale scene references after renaming swatches; re-run Apply Colors to all IDs after fixing theColorModuleasset.
Related
- Global Settings — register
ColorModule - RuntimeManager — bootstrap;
ColorSchemeManagerlives on the prefab - UI widgets — shared
ColorIDButton(RequireComponent(ColorID)),ColorSchemeToggle,ColorSchemeDropdown(_MolcaSDK/Code/Scripts/UI/)
Unity Editor
GlobalSettings asset: ColorModule in the module list; ColorModule Inspector: Default swatch with Primary/Secondary; GameObject with Color ID component showing swatch + targets.
