com.amanotes.themeengine
v1.5.0
Published
Theme management system with event-driven updates for sprites, text, and audio
Readme
ThemeEngine
Package: com.amanotes.themeengine
Version: 1.5.0
Event-driven theme management system for Unity. Change sprites, audio, text, colors, videos, and resource IDs at runtime with automatic UI updates. Themes can load an additive Unity scene; moods change values on the same scene objects (e.g. background per mood) without reloading.
Quick Start
1. Create a Theme Config
Right-click in Project → Create > ThemeEngine > Theme Config
Add your theme assets by key:
- Textures:
"background","button","icon" - Audio Clips:
"bgm","click_sound" - Text:
"title","score_label" - Videos:
"intro_video","background_video" - Colors:
"primary","accent" - Resource IDs:
"song_id","level_id"
2. Add Handler Components
ThemeSprite — auto-updates SpriteRenderer or Image:
- Add Component →
ThemeSprite - Assign ThemeConfig and key
ThemeHandler — generic handler for any asset type (sprite, text, audio, video, color):
- Add Component →
ThemeHandler - Assign ThemeConfig
- Add entries with keys and targets
ThemeBGVideo — video background with rhythm engine integration:
- Add Component →
ThemeBGVideo - Assign ThemeConfig, key, and VideoPlayer
3. Change Theme at Runtime
using Amanotes.Core;
[SerializeField] private ThemeConfig theme;
theme.SetText("title", "New Title");
theme.SetColor("primary", Color.red);
theme.SetResourceId("song_id", "song_123");
var color = theme.GetColorValue("primary", Color.white);
var text = theme.GetText("title")?.text;4. Listen to Changes
void OnEnable() => theme.OnAssetChanged += OnThemeChanged;
void OnDisable() => theme.OnAssetChanged -= OnThemeChanged;
void OnThemeChanged(string key, ThemeConfig.ThemeAsset asset)
{
if (key == "primary" && asset is ThemeConfig.ColorAsset color)
ApplyColor(color.value);
}WebGL Integration (SnapBeat)
Add ThemeCommandHandler to receive theme updates from web:
SetTexture(json)— downloads and applies texture by URLSetAudio(json)— downloads and applies audio clip by URLSetText(json)— sets text valueSetColor(json)— sets color from hex stringSetVideo(json)— sets video URLSetResourceId(json)— sets resource ID stringSetThemeElement(json)— multi-field part visibility, e.g.{"road":"off","foreground":"on"}. Omit a key to leave it unchanged; empty string clears that override (default on). SurvivesSwitchThemevia snapshot/restore; cleared byResetAll/ResetAsset {"id":"*"}.SetFloat(json)—{id, value}numeric ThemeConfig float (e.g. layout offsets). Key must already exist on the ThemeConfig.ResetAsset(json)—{id}clears one key (valued default restored, else cleared);{id:"*"}clears every ThemeConfig asset and theme-element overrides. Does not use theme-switchResetAll(which keeps host mood-bg overrides).
On start, ThemeCommandHandler posts the theme-config manifest (including themeElements from ThemeConfig.themeElements, each with options on/off) so the host can discover which part ids SetThemeElement accepts.
SendMessage target is the SnapBeatSDK GameObject (handler is a sibling component).
Components
| Component | Purpose |
|-----------|---------|
| ThemeConfig | ScriptableObject storing all theme data + SetMood |
| ThemePreset | Static blueprint/variant key→value (incl. scene string) |
| ThemeHandler | Generic handler routing fixed keys to targets |
| ThemeMoodHandler | Applies mood-{N}-{suffix} values to the same scene objects |
| ThemeSceneLoader | Additive load/unload of theme scenes |
| ThemeSceneRoot | Marker (+ anchors) on theme scene content |
| ThemeSprite | Auto-updates SpriteRenderer/Image (tint + camera fit) |
| ThemeBGVideo / RhythmBGVideo | Video background with rhythm sync |
| ThemeCommandHandler | SnapBeat web bridge for remote theming |
| ThemePartGate | Shows/hides wired content roots from a ResourceId (on/off; empty = visible) |
| VideoFitCamera | Auto-fits video sprite to camera/rect |
Dependencies
- Unity 2022.3+
com.unity.nuget.newtonsoft-json3.0.0- (Optional)
com.amanotes.snapbeat— enables web bridge - (Optional)
com.amanotes.magictilescore— enables rhythm sync
Version History
See CHANGELOG.md
