logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class UnityGraphicColorApplier

    Service that applies UiColorDelta tint changes to UGUI Graphic components. Analogous to UnityActivationApplier/UnityTransformApplier for activation and transform targets, but per-target this applier drives a whole COLLECTION of Graphics (every own Graphic under the target's root, not just one) rather than a single component.

    Inheritance
    object
    UnityGraphicColorApplier
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: Serenity.ProceduralAnimator.Infrastructure.Services
    Assembly: Serenity.UnityProceduralAnimator.Infrastructure.dll
    Syntax
    public class UnityGraphicColorApplier
    Remarks

    Adopt-base, not cache-once. A HUD element's own threshold/gauge coloring (HudRepeatedSpriteRenderer.ApplyValueColor and friends) can write a Graphic's color in the SAME Update, BEFORE the animator's own Tick runs (see UnityHudHostComponent.Update's ordering). Caching Base once at registration would make this applier fight that write every frame, snapping the Graphic back to a stale base the moment a threshold band changed it. Instead, every Apply(UiColorDelta) call re-checks whether the Graphic's LIVE color still matches what this applier itself last wrote (LastWritten); a mismatch means something else wrote it since, so the live color is adopted as the new Base before this tick's tint is computed on top of it.

    Never touches an undriven slot. A slot with no delta entry AND not currently Driven is left completely alone — this applier never becomes a standing color authority over a Graphic nothing is animating, mirroring UnityTransformApplier's position-facet latch.

    Constructors

    UnityGraphicColorApplier()

    Declaration
    public UnityGraphicColorApplier()

    Properties

    TargetCount

    Gets the number of registered UiColor targets.

    Declaration
    public int TargetCount { get; }
    Property Value
    Type Description
    int

    Methods

    Apply(UiColorDelta)

    Applies the UiColor delta to every registered target in a single self-correcting pass, mirroring Apply(ActivationDelta)/Apply(TransformDelta)'s shape — but fanning out per target across every collected GraphicColorSlot instead of one component.

    Declaration
    public void Apply(UiColorDelta delta)
    Parameters
    Type Name Description
    UiColorDelta delta

    This tick's UiColor overrides. May be null or empty — in that case every driven slot restores to its base and no target is re-scanned.

    Remarks

    Per target: if the delta carries an entry for it OR any of its slots is already Driven from a prior tick, and the root's UnityEngine.Transform.hierarchyCount has changed since the last (re-)collection, a re-scan (Serenity.ProceduralAnimator.Infrastructure.Services.UnityGraphicColorApplier.CollectNewSlots(Serenity.ProceduralAnimator.Infrastructure.Services.GraphicColorTargetInfo)) picks up any lazily-created slot (e.g. a STACK/SEGMENTED representation's Image slots) before this tick's per-slot pass runs. Then, per slot: adopt-base (see the class remarks) if the live color no longer matches what this applier itself last wrote; then resolve the desired color — Color.Lerp(Base, Base * Tint, Weight) when the target has an entry (latching Driven true), else Base when the slot was driven a prior tick but no longer is (latching it false), else nothing at all (never touch an undriven slot). Writes are guarded by a live-color comparison, and LastWritten always records whatever was actually resolved this tick — even when the write was skipped because it already matched — so the NEXT call's adopt-base check compares against the right value.

    ClearTargets()

    Clears all registered UiColor targets. Restores every currently-driven slot across every target first, for the same reason UnregisterTarget(TransformId) does it for a single target.

    Declaration
    public void ClearTargets()

    RegisterTarget(TransformId, RectTransform, Func<Transform, bool>)

    Registers a UiColor target: collects every own Graphic under root (excluding TMP_SubMeshUI — see Serenity.ProceduralAnimator.Infrastructure.Services.UnityGraphicColorApplier.CollectNewSlots(Serenity.ProceduralAnimator.Infrastructure.Services.GraphicColorTargetInfo)) and caches each one's live color as its base.

    Declaration
    public void RegisterTarget(TransformId id, RectTransform root, Func<Transform, bool> isForeignElementRoot)
    Parameters
    Type Name Description
    TransformId id

    Unique identifier for this target — a HUD element id.

    RectTransform root

    The element's content root to collect Graphics under.

    Func<Transform, bool> isForeignElementRoot

    Returns true for a descendant transform marking a DIFFERENT element's own root (so a reparented sibling's Graphics are never collected as this target's own) — see HudElementOwnComponentCollector's own remarks for why this is a caller-supplied predicate rather than a hard-coded type check. Null is treated as "nothing is foreign" (collect the whole sub-hierarchy).

    Remarks

    Re-registering an id already present in Serenity.ProceduralAnimator.Infrastructure.Services.UnityGraphicColorApplier._targets restores that target's currently-driven slots to their cached base FIRST, via the same Serenity.ProceduralAnimator.Infrastructure.Services.UnityGraphicColorApplier.RestoreDrivenSlots(Serenity.ProceduralAnimator.Infrastructure.Services.GraphicColorTargetInfo) helper UnregisterTarget(TransformId)/ClearTargets() use — before the fresh GraphicColorTargetInfo is built and its slots (re-)collected. Skipping that restore would have Serenity.ProceduralAnimator.Infrastructure.Services.UnityGraphicColorApplier.CollectNewSlots(Serenity.ProceduralAnimator.Infrastructure.Services.GraphicColorTargetInfo) read each Graphic's LIVE color as the new slot's Base — which, for a slot a delta entry was actively driving a moment ago, is a mid-tint value, not the true undriven base. A caller that re-registers the same id on every rebuild (a HUD element re-registered after a hierarchy change, say) would then corrupt that base permanently.

    RestoreDrivenSlots()

    Restores every currently-driven slot, across every registered target, to its cached base color and clears the driven latch. Reserved for explicit/teardown use — component OnDisable/OnDestroy — mirroring ResetToOriginalActive()/ResetToOriginals()'s role: nothing here runs per-tick, since Apply(UiColorDelta) is already self-correcting.

    Declaration
    public void RestoreDrivenSlots()

    UnregisterTarget(TransformId)

    Unregisters a UiColor target. Restores every currently-driven slot to its cached base color first — mirrors UnregisterTarget(TransformId)'s "restore before forgetting" shape, since once removed nothing will ever re-evaluate this target's slots again.

    Declaration
    public void UnregisterTarget(TransformId id)
    Parameters
    Type Name Description
    TransformId id

    The identifier of the target to unregister.

    In this article
    © 2026 Serenity. All Rights Reserved