IvanMurzak / Unity-Theme

Create palettes of colors and components for change specific color on a specific visual element. Very useful to UI.
MIT License
90 stars 6 forks source link

Changing theme at runtime #4

Closed codyrchildress closed 1 year ago

codyrchildress commented 1 year ago

Hi there,

Thank you for sharing this wonderful asset. Is it possible to change the theme at runtime? I am hoping to use this to implement a day/night mode on my game.

Cheers, Cody

IvanMurzak commented 1 year ago

@codyrchildress hi. Thank you! Yes, it works in Edit Time and in Play Time (runtime). You can create multiple different UI styles in the settings of the game. Or use for Day/Night cycles. Any approach works. All the Binders are subscribed to the color change event.

codyrchildress commented 1 year ago

Thank you for the reply. How would I raise this color change event, and how do I specify the theme I want to switch to?

IvanMurzak commented 1 year ago

@codyrchildress You can do that using C# API of the package.

// Link ThemeDatabase, 
// path to the file in your project: `/Assets/Resources/Unity-Theme Database.asset`
[SerializedField] ThemeDatabase themeDatabase;

// change the current theme to a new theme from existed themes list
themeDatabase.CurrentThemeIndex = 1;
iiidefektiii commented 1 year ago

Is it possible to get the list of themes from another script and set it instead of by name or index? Example. I create a ThemeManager script to call it by name but would be awesome if I could get the list of available themes and set it within in my script. this way each scene can have its own theme set.

I feel like it may be doable but you cannot access 'themes' because it is private.