コード例 #1
0
    public bool UpdateTurn()
    {
        bool updated = false;

        if (CurrentTurn.EndTime < DateTime.UtcNow)
        {
            if (CurrentTurn.Type.Equals(EntityType.Pedestrian))
            {
                if (crossingPedestrians.Count.Equals(0))
                {
                    ChangeTurn((CurrentTurn.Type.Equals(EntityType.Vehicle)) ? EntityType.Pedestrian : EntityType.Vehicle);
                    updated = true;
                }
                else
                {
                    TurnInCooldown = new TurnCooldownInfo()
                    {
                        Type           = CurrentTurn.Type,
                        CooldownFinish = System.DateTime.UtcNow.AddSeconds(TurnCooldownInfo.DEFAULT_COOLDOWN)
                    };
                }
            }
            else
            {
                ChangeTurn((CurrentTurn.Type.Equals(EntityType.Vehicle)) ? EntityType.Pedestrian : EntityType.Vehicle);
                updated = true;
            }
        }
        return(updated);
    }
コード例 #2
0
    public void ChangeTurn(EntityType _type, float _duration)
    {
        TurnInfo nextTurn = new TurnInfo
        {
            Type    = _type,
            EndTime = System.DateTime.UtcNow.AddSeconds(_duration)
        };
        TurnInfo pastTurn = CurrentTurn;

        CurrentTurn = nextTurn;
        if (_type.Equals(EntityType.Pedestrian))
        {
            TurnInCooldown = new TurnCooldownInfo()
            {
                Type           = pastTurn.Type,
                CooldownFinish = System.DateTime.UtcNow.AddSeconds(TurnCooldownInfo.DEFAULT_COOLDOWN)
            };
            pedestrianTurn = StartCoroutine(StartPedestrianTurn());
        }
        else
        {
            if (pedestrianTurn != null)
            {
                StopCoroutine(pedestrianTurn);
            }
        }
    }