コード例 #1
0
ファイル: SimulationManager.cs プロジェクト: knexer/Apophis
    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)));
        }
    }
コード例 #2
0
ファイル: SimulationManager.cs プロジェクト: knexer/Apophis
    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();
        }
    }
コード例 #3
0
ファイル: SimulationManager.cs プロジェクト: knexer/Apophis
 private void SimChanged()
 {
     UpdateForecast();
     OnSimChanged?.Invoke();
 }