private void InitializeInterpolationFactors() { directionInterpolationFactors = new InterpolationFactors { AnimatorValueName = ValueNameDirectionFactors, DiffFactor = 0.5f, InterpolatingPerFrameValue = 0.02f }; angleInterpolationFactors = new InterpolationFactors { AnimatorValueName = ValueNameAngle, DiffFactor = 2, InterpolatingPerFrameValue = 0.02f }; shootingLayerInterpolationFactors = new InterpolationFactors { AnimatorValueName = LayerNameShooting, InterpolatingPerFrameValue = 0.02f }; handsLayerInterpolationFactors = new InterpolationFactors { AnimatorValueName = LayerNameHands, InterpolatingPerFrameValue = 0.02f }; }
private void BeginInterpolation(float end, ref InterpolationFactors factors) { factors.Begin = factors.Actual; factors.End = end; factors.Interpolant = 0; factors.IsInterpolating = true; }
private void InterpolateLayerWeight(ref InterpolationFactors factors) { if (factors.IsInterpolating == true) { factors.Actual = Mathf.Lerp(factors.Begin, factors.End, factors.Interpolant); animator.SetLayerWeight(animator.GetLayerIndex(factors.AnimatorValueName), factors.Actual); factors.Interpolant += factors.InterpolatingPerFrameValue; if (factors.Interpolant > 1 || factors.Interpolant < 0) { factors.IsInterpolating = false; } } factors.LastFrame = factors.PresentFrame; }
private void InterpolateAnimation(ref InterpolationFactors factors) { if (Mathf.Abs(factors.LastFrame - factors.PresentFrame) > factors.DiffFactor) { BeginInterpolation(factors.PresentFrame, ref factors); } if (factors.IsInterpolating == true) { factors.Actual = Mathf.Lerp(factors.Begin, factors.End, factors.Interpolant); animator.SetFloat(factors.AnimatorValueName, factors.Actual); factors.Interpolant += factors.InterpolatingPerFrameValue; if (factors.Interpolant > 1 || factors.Interpolant < 0) { factors.IsInterpolating = false; } } factors.LastFrame = factors.PresentFrame; }