Logo

Styler Preset

Store reusable theme values in a StylerPreset asset

Overview

A StylerPreset asset holds the values shared by your UI. Components request entries by ID, which lets you create theme variants without changing each component’s references.

Styler Preset

Usage

In the Project window, choose Create -> Evo -> UI -> Styler Preset.

Add entries for your colors, fonts, audio, sprites, gradients, text styles, and shape styles.


Customization

Entry Types

TypeTypical use
AudioHover, click, open, and close sounds.
ColorText, surfaces, outlines, and state colors.
FontA font for each text provider, such as a TextMesh Pro font asset and a UniText font stack.
GradientShared color gradients.
SpriteReusable images and icons.
Text StyleTypography settings shared by text labels.
Shape StyleProcedural Shape appearance.

Fonts

A Font entry holds one font per text provider. With only TextMesh Pro installed, it shows a single Font Asset field; with UniText installed, it shows a TextMesh Pro and a UniText field. Components use the font that matches their text's provider, so one Font ID works with every provider. Font entries also pair fonts when converting existing text.

Shape Styles

A Shape Style’s Applies To flags select Graphic, Shape, Fill, Outline, Inner Shadow, and Outer Shadow groups. Use only the groups a style should own; the other settings stay local.

Keep On Global Apply

Turn on Keep On Global Apply under Settings for a preset that should not follow theme changes, such as a screen with its own look. Objects using this preset keep it when Styler.ApplyPreset() switches the theme, and they don't inherit Styler.PersistentPreset when enabled later. Styler.ApplyPresetTo() still changes them.

Renaming Entries

To rename an entry, type a new ID in its ID field and press Enter. Press Esc to cancel.

Components that use the old ID keep their values. The entry keeps the old ID as a former ID and shows Renamed from under its ID field. Until their references are updated, the components' ID dropdowns show the new name with the old one, such as Brand (was Primary).

If other presets have the same ID, a dialog asks whether to rename it there too. Choose Rename in All to keep your theme presets matching, or Only This Preset.

Entries added during the current Editor session are renamed without a former ID or a dialog, until a component picks them in a Styler dropdown.

ButtonResult
Update ReferencesOpens the ID Migrator with the former ID and the new ID filled in, so you can replace the old ID in scenes and prefabs.
ClearRemoves the former IDs after a confirmation. Components that still use them show the ID as missing.
Giving an entry an ID that another entry used before moves that ID to the new entry, and components that still use it follow the new entry. The rename dialog warns you first. Use Update References before reusing an old ID.

Managing Presets

Keep IDs consistent across themes. Save user preferences separately; runtime preset changes do not save them for the next session.


Public API

Use StylerPreset in the Evo.UI namespace. Prefer TryGet...() when an entry may be absent. Methods that take an ID also accept an entry's former IDs (Styler.Item.formerIDs), so code written for an old ID keeps working after a rename. A current ID always takes priority over a former one.

Fields

NameTypeDescription
audioItemsList<Styler.AudioItem>Named audio entries.
colorItemsList<Styler.ColorItem>Named colors.
fontItemsList<Styler.FontItem>Named fonts, with fontAsset for TextMesh Pro and providerFonts for other providers.
gradientItemsList<Styler.GradientItem>Named gradients.
spriteItemsList<Styler.SpriteItem>Named sprites.
textStyleItemsList<Styler.TextStyleItem>Named text styles.
shapeStyleItemsList<Styler.ShapeStyleItem>Named Procedural Shape styles.
updateModeStyler.UpdateModeAdaptive or Always update behavior.
keepOnGlobalApplyboolKeeps objects on this preset when another preset is applied globally or inherited from PersistentPreset.

Methods

NameParametersDescription
TryGetColor()string itemID, out Color colorLooks up a color and reports whether the ID exists. Returns bool.
GetColor()string itemIDReturns the color for an ID. Returns Color.
SetColor()string itemID, Color colorSets an entry's color, adding the entry if it is missing.
AddColor()string itemID, Color colorAdds a named color. If the ID is another entry's former ID, the new entry takes it over.
RemoveColor()string itemIDRemoves a color and reports success. Returns bool.
TryGetFont()string itemID, TextBackend backend, out Object fontLooks up the entry's font for a text provider. The font is null when the entry has none for it. Returns bool.
GetFont()string itemID, TextBackend backendReturns the entry's font for a text provider, or null. Returns Object.
SetFont()string itemID, TMP_FontAsset fontSets an entry's TextMesh Pro font, adding the entry if it is missing.
TryGetShapeStyleItem()string itemID, out Styler.ShapeStyleItem shapeStyleItemLooks up a Shape Style entry. Returns bool.
GetShapeStyleItem()string itemIDReturns a Shape Style entry. Returns Styler.ShapeStyleItem.
AddShapeStyle()string itemIDAdds a Shape Style with the given ID.
RemoveShapeStyle()string itemIDRemoves a Shape Style. Returns bool.
TryGetTextStyleItem()string itemID, out Styler.TextStyleItem textStyleItemLooks up a Text Style entry. Returns bool.
AddTextStyle()string itemIDAdds a Text Style.
RemoveTextStyle()string itemIDRemoves a Text Style. Returns bool.

Example

StylerPresetExample.cs
using UnityEngine;
using Evo.UI;

public class StylerPresetExample : MonoBehaviour
{
    [SerializeField] private StylerPreset sourcePreset;
    [SerializeField] private GameObject panel;
    private StylerPreset runtimePreset;

    private void Start()
    {
        runtimePreset = Instantiate(sourcePreset);
        if (runtimePreset.TryGetColor("Accent", out var accent))
        {
            runtimePreset.SetColor("Accent", accent * 0.8f);
            Styler.ApplyPresetTo(runtimePreset, panel, true, 0.2f);
        }
    }

    private void OnDestroy()
    {
        // Keep the clone alive for as long as the panel uses it.
        if (runtimePreset != null)
            Destroy(runtimePreset);
    }
}

On this page