Esempio n. 1
0
    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)));
        }
    }
Esempio n. 2
0
    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();
        }
    }
Esempio n. 3
0
 private void SimChanged()
 {
     UpdateForecast();
     OnSimChanged?.Invoke();
 }