better anim function

this is more efficient AND it'll produce more consistent results when starting an animation between tempo changes :D
(it no longer iterates through a list twice)
This commit is contained in:
AstrlJelly 2023-10-27 14:33:39 -04:00
parent cb4a3c5122
commit d696f53e63

View file

@ -66,8 +66,8 @@ namespace HeavenStudio.Util
if (!double.IsNaN(startBeat)) { if (!double.IsNaN(startBeat)) {
var cond = Conductor.instance; var cond = Conductor.instance;
var animClip = Array.Find(anim.runtimeAnimatorController.animationClips, x => x.name == animName); var animClip = Array.Find(anim.runtimeAnimatorController.animationClips, x => x.name == animName);
double animLength = cond.GetBeatFromSongPos(cond.GetSongPosFromBeat(startBeat) + animClip.length); double animLength = cond.SecsToBeats(animClip.length, cond.GetBpmAtBeat(startBeat));
pos = cond.GetPositionFromBeat(startBeat, animLength - startBeat) * timeScale; pos = cond.GetPositionFromBeat(startBeat, animLength) * timeScale;
} else { } else {
Debug.LogWarning("DoScaledAnimationFromBeatAsync()'s startBeat was NaN; using DoScaledAnimationAsync() instead."); Debug.LogWarning("DoScaledAnimationFromBeatAsync()'s startBeat was NaN; using DoScaledAnimationAsync() instead.");
} }