Skip to content

Instantly share code, notes, and snippets.

@Sztorm
Last active August 6, 2021 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sztorm/9bd608029802de1892f68d69bf4dd7cd to your computer and use it in GitHub Desktop.
Save Sztorm/9bd608029802de1892f68d69bf4dd7cd to your computer and use it in GitHub Desktop.
AnimationCurveUtils containing EaseIn and EaseOut functions. Public domain.
using UnityEngine;
public static class AnimationCurveUtils
{
/// <summary>
/// Creates an ease-in curve starting at timeStart, valueStart and ending at timeEnd,
/// valueEnd.
/// </summary>
/// <param name="timeStart">The start time for the ease-in curve.</param>
/// <param name="valueStart">The start value for the ease-in curve.</param>
/// <param name="timeEnd">The end time for the ease-in curve.</param>
/// <param name="valueEnd">The end value for the ease-in curve.</param>
/// <returns>The ease-in curve generated from the specified values.</returns>
public static AnimationCurve EaseIn(
float timeStart, float valueStart, float timeEnd, float valueEnd)
=> new AnimationCurve(
new Keyframe(timeStart, valueStart, inTangent: 0F, outTangent: 0F),
new Keyframe(timeEnd, valueEnd, inTangent: 2F, outTangent: 2F));
/// <summary>
/// Creates an ease-out curve starting at timeStart, valueStart and ending at timeEnd,
/// valueEnd.
/// </summary>
/// <param name="timeStart">The start time for the ease-out curve.</param>
/// <param name="valueStart">The start value for the ease-out curve.</param>
/// <param name="timeEnd">The end time for the ease-out curve.</param>
/// <param name="valueEnd">The end value for the ease-out curve.</param>
/// <returns>The ease-out curve generated from the specified values.</returns>
public static AnimationCurve EaseOut(
float timeStart, float valueStart, float timeEnd, float valueEnd)
=> new AnimationCurve(
new Keyframe(timeStart, valueStart, inTangent: 2F, outTangent: 2F),
new Keyframe(timeEnd, valueEnd, inTangent: 0F, outTangent: 0F));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment