From 41d9198f8eee36630380398f92b528b14a1f44f6 Mon Sep 17 00:00:00 2001 From: VladV Date: Thu, 25 Feb 2021 10:37:34 +0300 Subject: [PATCH] Add CurvedAnimation --- Runtime/AnimationController.cs | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Runtime/AnimationController.cs b/Runtime/AnimationController.cs index dc2fcc9..7f47009 100644 --- a/Runtime/AnimationController.cs +++ b/Runtime/AnimationController.cs @@ -182,6 +182,45 @@ public static IAnimation Animate(this IAnimatable parent, } } + public sealed class CurvedAnimation : IAnimation + { + private readonly IAnimation _controller; + private readonly Func _curve; + private readonly Func _reverseCurve; + + public CurvedAnimation(IAnimation controller, + Func curve, Func 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 : IAnimation { public bool IsAnimating => false;