Skip to main content

ScaleAnimator

A class in Root.Township, the global namespace.

Helper that scales a behaviour's transform in or out along "on" and "off" curves, using a coroutine on that behaviour.

Constructors​

MemberWhat it is
ScaleAnimator(MonoBehaviour behaviour, bool isInitiallyOn, Vector3 startScale, AnimationCurve on, AnimationCurve off, bool isDisallowingZero)Creates a ScaleAnimator from behaviour, isInitiallyOn, startScale, on, off and isDisallowingZero.

Fields​

7 private and internal fields
MemberWhat it is
private Coroutine animationRoutineThe running animation coroutine, null when idle.
private MonoBehaviour behaviourThe behaviour whose transform is scaled and that runs the coroutine.
private bool isDisallowingZeroKeeps scale at least 0.001 so the object never reaches zero.
private bool isOnBacking field for IsOn.
private AnimationCurve offScale curve played when turning off.
private AnimationCurve onScale curve played when turning on.
private Vector3 startScaleThe full scale that the curves multiply.

Properties​

MemberWhat it is
MonoBehaviour Behaviour { get; }The behaviour whose transform is scaled and which runs the coroutine.
bool IsAnimating { get; }True while the animation coroutine is running.
bool IsOn { get; set; }Whether it is (or is going) on. Setting it calls Set.
float Multiplier { get; private set; }Extra scale factor applied on top of the curves. Starts at 1.

Events​

MemberWhat it is
event Action FinishedRaised each time an animation run ends.

Methods​

MemberWhat it is
void Set(bool isOn)Turns on or off. Animates if the behaviour is active, otherwise jumps to the end scale.
void Stop()Stops the animation and jumps to the end scale.
protected virtual void SetScale(float scale)Applies a scale relative to the start scale, never below 0.001 if zero is disallowed.
1 private and internal method
MemberWhat it is
private IEnumerator Animate() (iterator)Coroutine that plays the on or off curve, and plays again if the state flipped meanwhile, then raises Finished.

Used in​

Members of other types that take, return or hold a ScaleAnimator: