Skip to content

Commit

Permalink
Add CurvedAnimation
Browse files Browse the repository at this point in the history
  • Loading branch information
vanifatovvlad committed Feb 25, 2021
1 parent 9d79243 commit 41d9198
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Runtime/AnimationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,45 @@ public static IAnimation<T> Animate<T>(this IAnimatable<T> parent,
}
}

public sealed class CurvedAnimation : IAnimation<float>
{
private readonly IAnimation<float> _controller;
private readonly Func<float, float> _curve;
private readonly Func<float, float> _reverseCurve;

public CurvedAnimation(IAnimation<float> controller,
Func<float, float> curve, Func<float, float> reverseCurve = null)
{
_controller = controller;
_curve = curve ?? (t => t);
_reverseCurve = reverseCurve ?? _curve;
}

public bool IsAnimating => _controller.IsAnimating;
public bool IsCompleted => _controller.IsCompleted;
public bool IsDismissed => _controller.IsDismissed;
public AnimationStatus Status => _controller.Status;

public float Value
{
get
{
switch (_controller.Status)
{
case AnimationStatus.Forward:
case AnimationStatus.Completed:
return _curve(_controller.Value);

case AnimationStatus.Reverse:
case AnimationStatus.Dismissed:
return _reverseCurve(_controller.Value);
default:
return _controller.Value;
}
}
}
}

public sealed class ConstAnimation<T> : IAnimation<T>
{
public bool IsAnimating => false;
Expand Down

0 comments on commit 41d9198

Please sign in to comment.