Class ProceduralLayerWeightScheduler
Owns which procedural layers one animator tracks and what each of them currently weighs: the blend ramp toward each layer's target weight, the per-animator activation stamps ON_ACTIVATE layers need, and the auto-deactivation of layers whose repeat window has elapsed.
Inherited Members
Namespace: Serenity.ProceduralAnimator.Infrastructure.Services
Assembly: Serenity.UnityProceduralAnimator.Infrastructure.dll
Syntax
public sealed class ProceduralLayerWeightScheduler
Remarks
Every piece of this state is per-animator and deliberately never lives on the shared
ProceduralLayerSO asset, since one layer asset can be shared by many animators that
activate it at different times. Extracted from ProceduralAnimatorComponent, which held five
collections and six methods for this concern alone.
Constructors
ProceduralLayerWeightScheduler()
Declaration
public ProceduralLayerWeightScheduler()
Fields
EvaluationWeightThreshold
Weight at or below which a layer contributes nothing, so evaluation skips it entirely.
Declaration
public const float EvaluationWeightThreshold = 0.001
Field Value
| Type | Description |
|---|---|
| float |
Properties
Layers
Every layer this animator tracks, in evaluation order: the seeded configuration first, then anything AddRuntimeLayers(IReadOnlyList<ProceduralLayerSO>, bool) appended. Null entries are preserved so evaluation order matches the authored configuration exactly.
Declaration
public IReadOnlyList<ProceduralLayerSO> Layers { get; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyList<ProceduralLayerSO> |
Methods
Activate(ProceduralLayerSO)
Snaps a layer's weight straight to full for one-shot or repeating ON_ACTIVATE playback — deliberately skipping the blend-in ramp, since the sequence's own step easing should own the motion shape rather than a ramp softening it. Re-activating an already-active layer clears its activation stamp, restarting its sequence from the top on the next evaluated frame.
Declaration
public void Activate(ProceduralLayerSO layer)
Parameters
| Type | Name | Description |
|---|---|---|
| ProceduralLayerSO | layer |
Remarks
Stamping is intentionally left to StampActivationAndResolveLayerTime(ProceduralLayerSO, float) on the first frame the layer's weight clears the evaluation threshold. Stamping eagerly here would record the PREVIOUS frame's time — activation normally happens between ticks — making the first evaluated frame read a layer-local time above zero instead of exactly zero.
AddRuntimeLayers(IReadOnlyList<ProceduralLayerSO>, bool)
Appends layers registered at runtime — e.g. a non-rig animator assembled entirely in code. A layer already tracked is skipped without touching its current weight.
Declaration
public void AddRuntimeLayers(IReadOnlyList<ProceduralLayerSO> layers, bool startInactive)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyList<ProceduralLayerSO> | layers | |
| bool | startInactive | When true, each newly-tracked layer starts silent instead of at Seed(IReadOnlyList<ProceduralLayerSO>, IReadOnlyList<RuleSO>, Action<ProceduralLayerSO>)'s usual "no controlling rule defaults to full weight" behavior, so it waits for an explicit Activate(ProceduralLayerSO) instead of firing immediately on registration. |
Blend(float)
Advances every tracked layer's current weight toward its target. The first tick after Seed(IReadOnlyList<ProceduralLayerSO>, IReadOnlyList<RuleSO>, Action<ProceduralLayerSO>) snaps instead of ramping, so an always-active layer contributes from frame zero.
Declaration
public void Blend(float deltaTime)
Parameters
| Type | Name | Description |
|---|---|---|
| float | deltaTime |
Deactivate(ProceduralLayerSO)
Snaps a layer's weight straight to zero (no blend-out ramp, mirroring Activate(ProceduralLayerSO)) and removes its activation stamp.
Declaration
public void Deactivate(ProceduralLayerSO layer)
Parameters
| Type | Name | Description |
|---|---|---|
| ProceduralLayerSO | layer |
DeactivateLayersPastTheirRepeatWindow(float)
Deactivates every activated ON_ACTIVATE layer whose sequence has repeated RepeatCount times. A repeat count of zero loops forever and never auto-deactivates, and so does a layer with no natural end (a zero-length sequence, e.g. the base layer default).
Declaration
public void DeactivateLayersPastTheirRepeatWindow(float currentTime)
Parameters
| Type | Name | Description |
|---|---|---|
| float | currentTime |
Remarks
Call once per tick AFTER layers have been evaluated for the frame, so a layer's final repeat still gets one last evaluation before it stops contributing.
GetWeight(ProceduralLayerSO)
Gets a tracked layer's current weight, or zero for a layer this animator does not track.
Declaration
public float GetWeight(ProceduralLayerSO layer)
Parameters
| Type | Name | Description |
|---|---|---|
| ProceduralLayerSO | layer |
Returns
| Type | Description |
|---|---|
| float |
IsTracking(ProceduralLayerSO)
Whether this animator tracks the layer at all, so a caller can skip work it would discard.
Declaration
public bool IsTracking(ProceduralLayerSO layer)
Parameters
| Type | Name | Description |
|---|---|---|
| ProceduralLayerSO | layer |
Returns
| Type | Description |
|---|---|
| bool |
ResetAll()
Silences every tracked layer and drops every activation stamp. Dropping the stamps is what stops a layer silenced this way from resuming mid-sequence: a later direct SetTargetWeight(ProceduralLayerSO, float) call (bypassing Activate(ProceduralLayerSO)) would otherwise read a stale activation time, and DeactivateLayersPastTheirRepeatWindow(float) would keep measuring against it.
Declaration
public void ResetAll()
Seed(IReadOnlyList<ProceduralLayerSO>, IReadOnlyList<RuleSO>, Action<ProceduralLayerSO>)
Adopts the resolved configuration as this animator's starting layer set. A layer no rule controls defaults to full weight (it is always active); a rule-controlled layer starts silent and waits for its rule to raise it.
Declaration
public void Seed(IReadOnlyList<ProceduralLayerSO> layers, IReadOnlyList<RuleSO> rules, Action<ProceduralLayerSO> onLayerWithoutControllingRule)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyList<ProceduralLayerSO> | layers | |
| IReadOnlyList<RuleSO> | rules | |
| Action<ProceduralLayerSO> | onLayerWithoutControllingRule | Reports each always-active layer, so the caller can surface it in a development build without this type knowing about logging. |
SetRuleDrivenTargetWeight(ProceduralLayerSO, float)
Sets a tracked layer's target weight straight from a rule, without the clamp SetTargetWeight(ProceduralLayerSO, float) applies to externally supplied values.
Declaration
public void SetRuleDrivenTargetWeight(ProceduralLayerSO layer, float weight)
Parameters
| Type | Name | Description |
|---|---|---|
| ProceduralLayerSO | layer | |
| float | weight |
SetTargetWeight(ProceduralLayerSO, float)
Sets a tracked layer's target weight, letting Blend(float) ramp toward it.
Declaration
public void SetTargetWeight(ProceduralLayerSO layer, float weight)
Parameters
| Type | Name | Description |
|---|---|---|
| ProceduralLayerSO | layer | |
| float | weight |
StampActivationAndResolveLayerTime(ProceduralLayerSO, float)
Returns how long an ON_ACTIVATE layer has been running, stamping its
activation at currentTime the first time it is asked.
Declaration
public float StampActivationAndResolveLayerTime(ProceduralLayerSO layer, float currentTime)
Parameters
| Type | Name | Description |
|---|---|---|
| ProceduralLayerSO | layer | |
| float | currentTime |
Returns
| Type | Description |
|---|---|
| float |
Remarks
Stamping lazily, with the evaluating tick's own clock, guarantees layer-local time starts at exactly
zero on the first evaluated frame no matter which path armed the layer — Activate(ProceduralLayerSO), a
SetLayerWeight rule, or AddRuntimeLayers(IReadOnlyList<ProceduralLayerSO>, bool) with startInactive: false — and no
matter what clock drives the tick.
SummarizeActiveWeights(out int, out float)
Summarizes how much weight is live this frame, for development-build tracing.
Declaration
public void SummarizeActiveWeights(out int activeLayerCount, out float totalWeight)
Parameters
| Type | Name | Description |
|---|---|---|
| int | activeLayerCount | |
| float | totalWeight |
TryGetWeight(ProceduralLayerSO, out float)
Gets a tracked layer's current weight without collapsing "not tracked" into zero.
Declaration
public bool TryGetWeight(ProceduralLayerSO layer, out float weight)
Parameters
| Type | Name | Description |
|---|---|---|
| ProceduralLayerSO | layer | |
| float | weight |
Returns
| Type | Description |
|---|---|
| bool |