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.
- Listed in Global namespace: A to B
- Inherits or implements
MonoBehaviour,IIgnoreForStaticFlatten,IDontSplit - Derived types
BuildingAnimationEvent,BuildingAnimationUnityEvent - Attributes
SelectionBase
Constructors
| Member | What it is |
|---|---|
BuildingAnimation() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
18 private and internal fields
| Member | What it is |
|---|---|
private Vector3 animationDirection | Local direction parts are ordered along and fly in from. |
private BuildingAnimationEvent animationFinished | Serialized event raised when the animation ends. |
private Transform animationParent | Backing field for AnimationParent. |
private BuildingAnimationEvent animationStarted | Serialized event raised when the animated build starts. |
private float baseDistance | Distance parts start from their final position when generated. |
private AnimationCurve durationMultiplier | Curve over overall progress that scales each part's insert time. Later parts go faster by default. |
private PooledObjectDefinition effectOnAppear | Pooled effect spawned where a part appears, unless the part overrides it. |
private PooledObjectDefinition effectOnPosition | Pooled effect spawned where a part lands, unless the part overrides it. |
private bool hasMovingColliders | Serialized flag that nothing reads in this build. |
private float insertDuration | Base seconds for one part to move into place. |
private bool isPlayingOnEnable | Whether the animation plays when the object is enabled. |
private bool isRepeatable | Keeps the parts (hidden) after playing so the animation can play again. |
private bool isSkippingAnimation | When set, Play jumps straight to the end. Cleared when the animation finishes. |
private List<AnimationPart> movingParts | Backing field for MovingParts. |
private float overallDuration | Seconds over which all parts are released. |
private AnimationCurve releaseTime | Curve from overall progress to the fraction of parts released. |
private SoundEffect soundOnAppear | Sound played where a part appears, unless the part overrides it. |
private SoundEffect soundOnPosition | Sound played where a part lands, unless the part overrides it. |
Properties
| Member | What 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
| Member | What it is |
|---|---|
event Action AnimationFinished | Raised when the last part lands, or straight away with PlayInstant. |
Methods
8 private and internal methods
| Member | What 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: