Skip to main content

BuildingAnimation

A class in Root.Township, the global namespace.

Plays a build-up animation where an object's parts fly in one by one along a direction, with sounds and effects. Parts are set up in the editor.

Constructors​

MemberWhat it is
BuildingAnimation()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

18 private and internal fields
MemberWhat it is
private Vector3 animationDirectionLocal direction parts are ordered along and fly in from.
private BuildingAnimationEvent animationFinishedSerialized event raised when the animation ends.
private Transform animationParentBacking field for AnimationParent.
private BuildingAnimationEvent animationStartedSerialized event raised when the animated build starts.
private float baseDistanceDistance parts start from their final position when generated.
private AnimationCurve durationMultiplierCurve over overall progress that scales each part's insert time. Later parts go faster by default.
private PooledObjectDefinition effectOnAppearPooled effect spawned where a part appears, unless the part overrides it.
private PooledObjectDefinition effectOnPositionPooled effect spawned where a part lands, unless the part overrides it.
private bool hasMovingCollidersSerialized flag that nothing reads in this build.
private float insertDurationBase seconds for one part to move into place.
private bool isPlayingOnEnableWhether the animation plays when the object is enabled.
private bool isRepeatableKeeps the parts (hidden) after playing so the animation can play again.
private bool isSkippingAnimationWhen set, Play jumps straight to the end. Cleared when the animation finishes.
private List<AnimationPart> movingPartsBacking field for MovingParts.
private float overallDurationSeconds over which all parts are released.
private AnimationCurve releaseTimeCurve from overall progress to the fraction of parts released.
private SoundEffect soundOnAppearSound played where a part appears, unless the part overrides it.
private SoundEffect soundOnPositionSound played where a part lands, unless the part overrides it.

Properties​

MemberWhat it is
Transform AnimationParent { get; }Parent transform for the animated parts.
List<AnimationPart> MovingParts { get; }The parts that fly in, in release order.
Func<AnimationPart, float, bool, IEnumerator, IEnumerator> PreInsertAnimation { get; set; }Optional hook that wraps each part's animation, for an extra step before it flies in.

Events​

MemberWhat it is
event Action AnimationFinishedRaised when the last part lands, or straight away with PlayInstant.

Methods​

MemberWhat it is
void GenerateParts(Transform[] components)Editor: makes an animation part for each transform, moving out sideways from the animation direction.
void OrderComponents(Component[] components)Editor: sorts components along the animation direction.
void Play()Plays the animation from the start, or finishes instantly if skipping is set.
void PlayInstant()Finishes at once. The temporary parts are hidden if repeatable or skipping, otherwise destroyed.
void SetIsSkippingAnimation(bool isSkipping)Makes the next Play finish instantly. Resets after the animation finishes.
void Stop()Stops the animation and hides all parts again.
8 private and internal methods
MemberWhat it is
private IEnumerator AnimatePart(AnimationPart part, float duration, bool isLast) (iterator)Coroutine that plays the appear effects, moves one part from its start to final position over the duration, then plays the land effects. The last part finishes the animation.
private void Awake()Hides every moving part, recalculates their positions and hooks OnAnimationFinished. Stop calls it again to reset.
private void OnAnimationFinished()Clears the skip flag once the animation ends.
private void OnDestroy()Unhooks OnAnimationFinished.
private void OnDrawGizmosSelected()Draws an arrow along the animation direction.
private void OnEnable()Plays the animation if isPlayingOnEnable is set.
private IEnumerator PlayAnimation() (iterator)Coroutine that releases parts over overallDuration following the releaseTime curve and starts each part's move.
private bool ShouldKeepAnimationParts(AnimationPart part)Whether parts are hidden rather than destroyed at the end: true when repeatable or skipping.

Used in​

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