Skip to content

Instantly share code, notes, and snippets.

@GeorgiyRyaposov
Created September 23, 2021 04:26
Show Gist options
  • Save GeorgiyRyaposov/ef5c5073858b4172ed2a7686cb814765 to your computer and use it in GitHub Desktop.
Save GeorgiyRyaposov/ef5c5073858b4172ed2a7686cb814765 to your computer and use it in GitHub Desktop.
When you need to snap value, e.g. each 45 from 0 to 360
private AnimationCurve GetSnapCurve(float min, float max, float snapAt, float snapAmount, WrapMode wrapMode = WrapMode.Clamp)
{
var keyFrames = new List<Keyframe>
{
new Keyframe(0, min),
new Keyframe(1, max)
};
for (float i = snapAt; i < max; i += snapAt)
{
keyFrames.Add(new Keyframe(i / max, i, 0, 0, snapAmount, snapAmount));
}
return new AnimationCurve(keyFrames.ToArray())
{
preWrapMode = wrapMode,
postWrapMode = wrapMode
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment