Skip to content

Commit

Permalink
Merge pull request #18 from dubit/development
Browse files Browse the repository at this point in the history
Release 1.3.1
  • Loading branch information
FancySensei authored Mar 21, 2019
2 parents 781b7c9 + 8cc4658 commit b356b78
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 30 deletions.
28 changes: 10 additions & 18 deletions Scripts/CustomAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ namespace DUCK.Tween
public class CustomAnimation : TimedAnimation
{
public float CurrentValue { get; private set; }
public float From { get; private set; }
public float To { get; private set; }
public float From { get; set; }
public float To { get; set; }

/// <summary>
/// Custom Animation is always true because customUpdate cannot be null
/// </summary>
public override bool IsValid { get { return true; } }
public override bool IsValid => true;

private readonly Action<float> customUpdate;

Expand All @@ -31,11 +31,7 @@ public class CustomAnimation : TimedAnimation
public CustomAnimation(Action<float> customUpdate, float from = 0, float to = 1.0f, float duration = 1.0f, Func<float, float> easingFunction = null)
: base((GameObject)null, duration, easingFunction)
{
if (customUpdate == null)
{
throw new ArgumentNullException("customUpdate");
}
this.customUpdate = customUpdate;
this.customUpdate = customUpdate ?? throw new ArgumentNullException(nameof(customUpdate));
From = from;
To = to;
}
Expand All @@ -51,15 +47,15 @@ protected override void Refresh(float progress)
/// </summary>
public class CustomAnimation<T> : TimedAnimation
{
public T Target { get; private set; }
public T Target { get; }
public float CurrentValue { get; private set; }
public float From { get; private set; }
public float To { get; private set; }
public float From { get; set; }
public float To { get; set; }

/// <summary>
/// Custom Animation is always true because customUpdate cannot be null
/// </summary>
public override bool IsValid { get { return Target != null; } }
public override bool IsValid => Target != null;

private readonly Action<T, float> customUpdate;

Expand All @@ -78,14 +74,10 @@ public CustomAnimation(T target, Action<T, float> customUpdate, float from = 0,
{
if (target == null)
{
throw new ArgumentNullException("target");
}
if (customUpdate == null)
{
throw new ArgumentNullException("customUpdate");
throw new ArgumentNullException(nameof(target));
}
Target = target;
this.customUpdate = customUpdate;
this.customUpdate = customUpdate ?? throw new ArgumentNullException(nameof(customUpdate));
From = from;
To = to;
}
Expand Down
24 changes: 12 additions & 12 deletions Scripts/TimedAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,33 @@ public abstract class TimedAnimation : AbstractAnimation, IAnimationPlaybackCont
/// You can assign a customised Animation Driver to replace the default one.
/// You can also set it to null -- and it will force the animation using the default driver from DUCK.
/// </summary>
public static IAnimationDriver DefaultDriver { get { return defaultDriver; } set { defaultDriver = value; } }
private static IAnimationDriver defaultDriver = DefaultAnimationDriver.Instance;
public static IAnimationDriver DefaultDriver { get; set; } = DefaultAnimationDriver.Instance;

public IAnimationDriver AnimationDriver
{
get { return animationDriver ?? (animationDriver = DefaultDriver ?? DefaultAnimationDriver.Instance); }
set { animationDriver = value; }
get => animationDriver ?? (animationDriver = DefaultDriver ?? DefaultAnimationDriver.Instance);
set => animationDriver = value;
}
private IAnimationDriver animationDriver;

/// <summary>
/// The target gameobject of the this animation
/// </summary>
public GameObject TargetObject { get; private set; }
public GameObject TargetObject { get; }

/// <summary>
/// The RectTransform of the target game object, null if it doesn't have one
/// </summary>
public RectTransform TargetRectTransform { get; private set; }
public RectTransform TargetRectTransform { get; }

/// <summary>
/// The duration of the timed animation
/// Duration will always clamp to >= 0
/// </summary>
public float Duration
{
get { return duration; }
set { duration = Mathf.Max(0f, value); }
get => duration;
set => duration = Mathf.Max(0f, value);
}
private float duration;

Expand All @@ -58,12 +57,12 @@ public float Duration
/// </summary>
public bool IsReversed { get; private set; }

public override bool IsValid { get { return TargetObject != null || TargetRectTransform != null; } }
public override bool IsValid => TargetObject != null || TargetRectTransform != null;

private readonly Func<float, float> easingFunction;

private bool IsComplete { get { return IsReversed ? Progress <= 0f : Progress >= 1f; } }
private float Progress { get { return Mathf.Clamp01(CurrentTime / Duration); } }
private bool IsComplete => IsReversed ? Progress <= 0f : Progress >= 1f;
private float Progress => Mathf.Clamp01(CurrentTime / Duration);

protected TimedAnimation() {}

Expand Down Expand Up @@ -103,7 +102,8 @@ public override void Play(Action onComplete, Action onAbort = null)
}

base.Play(onComplete, onAbort);
Refresh(CurrentTime = IsReversed ? Duration : 0f);
CurrentTime = IsReversed ? Duration : 0f;
Refresh(Progress);
}
else
{
Expand Down

0 comments on commit b356b78

Please sign in to comment.