This commit is contained in:
NotAKidoS 2023-03-24 20:50:21 -05:00
parent 9cc62a961c
commit 3a3cb1879c
2 changed files with 10 additions and 13 deletions

View file

@ -27,17 +27,14 @@ public class BadAnimatorFix : MonoBehaviour
{
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(layerIndex);
AnimatorTransitionInfo transitionInfo = animator.GetAnimatorTransitionInfo(layerIndex);
// Skip if state doesn't loop or if mid-transition
if (!stateInfo.loop || transitionInfo.fullPathHash != 0) continue;
// Skip if state hasn't looped enough
if (stateInfo.normalizedTime > StateLimit)
{
float rewindOffset = (stateInfo.normalizedTime % 1f) + 10f;
animator.Play(stateInfo.fullPathHash, layerIndex, rewindOffset);
rewound = true;
}
// Skip if mid-transition
if (transitionInfo.fullPathHash != 0) continue;
// Skip if anim doesn't loop, or hasn't looped enough
if (stateInfo.normalizedTime < StateLimit) continue;
// Rewind state, with 10f as buffer, to account for reasonable use of ExitTime
float offset = 10f + (stateInfo.normalizedTime % 1f);
animator.Play(stateInfo.fullPathHash, layerIndex, offset);
rewound = true;
}
if (rewound)
@ -45,7 +42,7 @@ public class BadAnimatorFix : MonoBehaviour
PlayableExtensions.SetTime<Playable>(animator.playableGraph.GetRootPlayable(0), 0);
}
}
if (BadAnimatorFixMod.EntryLogging.Value)
{
string message = rewound ? $"Rewound animator and playable {animator}." : $"Animator did not meet criteria to rewind {animator}.";