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
| Member | What 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
| Member | What it is |
|---|
private Coroutine animationRoutine | The running animation coroutine, null when idle. |
private MonoBehaviour behaviour | The behaviour whose transform is scaled and that runs the coroutine. |
private bool isDisallowingZero | Keeps scale at least 0.001 so the object never reaches zero. |
private bool isOn | Backing field for IsOn. |
private AnimationCurve off | Scale curve played when turning off. |
private AnimationCurve on | Scale curve played when turning on. |
private Vector3 startScale | The full scale that the curves multiply. |
Properties
| Member | What 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
| Member | What it is |
|---|
event Action Finished | Raised each time an animation run ends. |
Methods
| Member | What 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
| Member | What 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: