Skip to main content

HoverAnimator

A class in Root.Township, the global namespace.

Bobs a set of transforms around their start positions using per-axis curves, plus any DragTrigger pull. Can stop and ease back to the start.

Constructors​

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

Fields​

14 private and internal fields
MemberWhat it is
private Vector3 animationLengthsLength of each axis curve.
private Vector3 animationStartTimesFirst key time of each axis curve.
private HoverAnimator.HoverAnimationState[] animationStatesPer transform state: start position, time offset and drag trigger.
private Dictionary<SnapAxis, AnimationCurve> axisCurvesAxis to curve lookup.
private AnimationCurve hoverXAnimationCurve for the x offset.
private AnimationCurve hoverYAnimationCurve for the y offset.
private AnimationCurve hoverZAnimationCurve for the z offset.
private bool isPlayingWhether the hover is running. Starts true.
private bool isRandomisedOffsetPerTransformNot read in this build: offsets are always random.
private float magnitudeScaleMultiplier on the hover offset.
private float resetMovementSpeedSpeed used to move back to the start after stopping.
private Coroutine resetPositionRoutineThe running return to start coroutine, if any.
private float timeScaleMultiplier on animation time.
private Transform[] transformsToAnimateThe transforms that hover.

Methods​

MemberWhat it is
void PlayAnimation()Stops any return to start and resumes hovering.
void StopAnimation()Stops hovering and starts easing back to the start position.
7 private and internal methods
MemberWhat it is
private float EvaluateAnimation(SnapAxis axis, HoverAnimator.HoverAnimationState animationState, Func<Vector3, float> getValue)Samples one axis curve for a transform at the current time with its offset, looping over the curve length.
private void LateUpdate()While playing, sets each transform's local position to start plus the scaled hover offset and drag pull.
private void OnValidate()Rebuilds the animation setup when edited.
private IEnumerator ReturnToStartPosition() (iterator)Coroutine: moves the first transform back to its start position at resetMovementSpeed. Other transforms stay where they are.
private void SetupAnimation()Reads each curve's start time and length and builds the axis to curve map.
private void SetupAnimationStates()Stores each transform's start position, a random time offset and its DragTrigger.
private void Start()Sets up the animation.

Used in​

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