private IEnumerator FastForwardTo(int nextTime) { float initialTime = Time.time; int initialTimeStep = ActualSims.CurrentSim.CurrentTime; while (ActualSims.CurrentSim.CurrentTime < nextTime) { ActualSims.AdvanceTime(); OnSimChanged?.Invoke(); float acceleratingSpeed = Mathf.Pow(SimStepAnimationSpeedupRatioPerStep, ActualSims.CurrentSim.CurrentTime - initialTimeStep); float deceleratingSpeed = Mathf.Pow(SimStepAnimationSpeedupRatioPerStep, nextTime - ActualSims.CurrentSim.CurrentTime); float speed = Mathf.Min(acceleratingSpeed, deceleratingSpeed); yield return(new WaitForSeconds(Mathf.Max(SimStepAnimationSeconds / speed, SimStepAnimationMinSeconds))); } }
private IEnumerator BuyUpgradeCoroutine(Upgrade upgrade) { IsLocked = true; OnSimChanged?.Invoke(); try { int?timeToBuy = GetTimeToPurchase(upgrade); if (timeToBuy == null) { throw new ArgumentException($"Upgrade {upgrade.name} can't be afforded before the end of time!"); } yield return(FastForwardTo(ActualSims.CurrentSim.CurrentTime + timeToBuy.Value)); ActualSims.CurrentSim.BuyUpgrade(upgrade); SimChanged(); } finally { IsLocked = false; OnSimChanged?.Invoke(); } }
private void SimChanged() { UpdateForecast(); OnSimChanged?.Invoke(); }