Created
September 23, 2021 04:26
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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