private IEnumerator AnimateSpeedTo(float value, PhysicsAnimationCurve curveFrom, PhysicsAnimationCurve curveTo) { float elapsed = 0.0f; float duration = curveFrom.TimeMultiplier; float startSpeed = gameSpeed; if (Mathf.Sign(value) != Mathf.Sign(gameSpeed) && gameSpeed != 0) { while (elapsed < duration) { if (IsPaused) { yield return(new WaitForEndOfFrame()); continue; } gameSpeed = curveFrom.Evaluate(gameSpeed, duration - elapsed) * startSpeed; elapsed += Time.deltaTime; OnSpeedChangeEvent?.Invoke(); yield return(new WaitForEndOfFrame()); } elapsed = gameSpeed = 0; } duration = curveTo.TimeMultiplier; while (elapsed < duration) { if (IsPaused) { yield return(new WaitForEndOfFrame()); continue; } gameSpeed = curveTo.Evaluate(gameSpeed, elapsed) * value; elapsed += Time.deltaTime; OnSpeedChangeEvent?.Invoke(); yield return(new WaitForEndOfFrame()); } gameSpeed = value; OnSpeedChangeEvent?.Invoke(); }
public void Stop() { if (hasEnded) { return; } if (runner != null && timeInRoutine != null) { runner.StopCoroutine(timeInRoutine); } IsPlayingNormal.Value = false; isStopped = true; isReversing = false; gameSpeed = 0; OnSpeedChangeEvent?.Invoke(); }