コード例 #1
0
    // check lights during an emergency
    private void CheckMoveInEmergency()
    {
        for (int i = _vehiclesOnZ.Count - 1; i >= 0; i--)
        {
            VehicleBehaviour vehicle = _vehiclesOnZ[i];
            foreach (LightStopZ lightStop in GetComponentsInChildren <LightStopZ>())
            {
                if (ReferenceEquals(lightStop.VehicleAtLight, vehicle) &&
                    lightStop.gameObject.name.Equals("East to West") &&
                    zEast.greenLight.activeSelf)
                {
                    vehicle.SetNextRoad();
                    vehicle.Continue();
                    _vehiclesOnZ.Remove(vehicle);
                    break;
                }
                if (ReferenceEquals(lightStop.VehicleAtLight, vehicle) &&
                    lightStop.gameObject.name.Equals("West to East") &&
                    zWest.greenLight.activeSelf)
                {
                    vehicle.SetNextRoad();
                    vehicle.Continue();
                    _vehiclesOnZ.Remove(vehicle);
                    break;
                }
                vehicle.Stop();
            }
        }

        for (int i = _vehiclesOnX.Count - 1; i >= 0; i--)
        {
            VehicleBehaviour vehicle = _vehiclesOnX[i];
            foreach (LightStopX lightStop in GetComponentsInChildren <LightStopX>())
            {
                if (ReferenceEquals(lightStop.VehicleAtLight, vehicle) &&
                    lightStop.gameObject.name.Equals("South to North") &&
                    xSouth.greenLight.activeSelf)
                {
                    vehicle.SetNextRoad();
                    vehicle.Continue();
                    _vehiclesOnX.Remove(vehicle);
                    break;
                }
                if (ReferenceEquals(lightStop.VehicleAtLight, vehicle) &&
                    lightStop.gameObject.name.Equals("North to South") &&
                    xNorth.greenLight.activeSelf)
                {
                    vehicle.SetNextRoad();
                    vehicle.Continue();
                    _vehiclesOnX.Remove(vehicle);
                    break;
                }
                vehicle.Stop();
            }
        }
    }
コード例 #2
0
 private void OnTriggerExit(Collider other)
 {
     if (other.gameObject.GetComponent <CarFrontCollider>() == null)
     {
         return;
     }
     VehicleAtLight = other.gameObject.GetComponentInParent <VehicleBehaviour>();
     if (VehicleAtLight == null)
     {
         return;
     }
     if (VehicleAtLight.NextRoad == null && !VehicleAtLight.IsUnableToMove)
     {
         VehicleAtLight.SetNextRoad();
     }
     _controller.CheckRemoveZ(VehicleAtLight);
     VehicleAtLight.BuildNextPath();
     VehicleAtLight.LightStopZs.Remove(this);
     VehicleAtLight = null;
 }
コード例 #3
0
    // move vehicles if able
    private void MoveVehicles()
    {
        for (int i = _vehiclesTurning.Count - 1; i >= 0; i--)
        {
            VehicleBehaviour vehicle = _vehiclesTurning[i];
            if (Handler.IsSomethingOnFire && vehicle.CompareTag("firebrigade"))
            {
                vehicle.SetNextRoad();
                vehicle.Continue();
                _vehiclesTurning.Remove(vehicle);
                continue;
            }
            if (vehicle.NextRoad == null)
            {
                vehicle.SetNextRoad();
            }

            if (vehicle.NextRoad != null)
            {
                if (vehicle.NextRoad.GetComponent <WaypointPath>().GetCongestion() >
                    vehicle.NextRoad.GetComponent <WaypointPath>().CongestionThreshold)
                {
                    vehicle.SetNextRoad();
                }
            }

            if (vehicle.IsUnableToMove)
            {
                vehicle.Stop();
            }
            else if (vehicle.LeftJunctionLeave || vehicle.IsGoingStraightAtJunction)
            {
                _vehiclesTurning.Remove(vehicle);
            }
            else if (vehicle.RightJunctionCrossing)
            {
                if (_rightLane.TrafficInLane)
                {
                    vehicle.Stop();
                }
                else
                {
                    vehicle.Continue();
                    _vehiclesTurning.Remove(vehicle);
                }
            }
            else if (vehicle.RightJunctionJoin)
            {
                if (_rightLane.TrafficInLane || _leftLane.TrafficInLane)
                {
                    vehicle.Stop();
                }
                else
                {
                    vehicle.Continue();
                    _vehiclesTurning.Remove(vehicle);
                }
            }
            else if (vehicle.LeftJunctionJoin)
            {
                if (_rightLane.TrafficInLane)
                {
                    vehicle.Stop();
                }
                else
                {
                    vehicle.Continue();
                    _vehiclesTurning.Remove(vehicle);
                }
            }
        }
    }
コード例 #4
0
    // move traffic on Z if the coast is clear
    private void MoveTrafficOnZ()
    {
        int vehiclesTurningRight = 0;

        for (int i = _vehiclesOnZ.Count - 1; i >= 0; i--)
        {
            VehicleBehaviour vehicle = _vehiclesOnZ[i];
            if (vehicle.NextRoad == null)
            {
                vehicle.SetNextRoad();
            }
            if (vehicle.NextRoad != null)
            {
                if (vehicle.NextRoad.GetComponent <WaypointPath>().GetCongestion() >
                    vehicle.NextRoad.GetComponent <WaypointPath>().CongestionThreshold)
                {
                    print(vehicle.gameObject.name + " setting another road on " + gameObject.name);
                    vehicle.SetNextRoad();
                }
            }
            if (vehicle.IsUnableToMove)
            {
                vehicle.Stop();
            }
            else if (vehicle.IsGoingStraightAtCross || vehicle.LeftCross ||
                     vehicle.IsGoingStraightAtJunction || vehicle.LeftJunctionLeave)
            {
                foreach (LightStopZ lightStop in GetComponentsInChildren <LightStopZ>())
                {
                    if (!ReferenceEquals(lightStop.VehicleAtLight, vehicle))
                    {
                        continue;
                    }
                    if (((vehicle.IsGoingStraightAtCross || vehicle.IsGoingStraightAtJunction) && !lightStop.StraightOn.TrafficInLane && !lightStop.Front.TrafficInLane) ||
                        ((vehicle.LeftCross || vehicle.LeftJunctionLeave) && !lightStop.LeftTurn.TrafficInLane && !lightStop.Front.TrafficInLane)
                        )
                    {
                        vehicle.Continue();
                        _vehiclesOnZ.Remove(vehicle);
                    }
                    else
                    {
                        vehicle.Stop();
                    }
                }
            }
            else
            {
                foreach (LightStopZ lightStop in GetComponentsInChildren <LightStopZ>())
                {
                    if (lightStop.CrossLane == null)
                    {
                        continue;
                    }
                    if (ReferenceEquals(lightStop.VehicleAtLight, vehicle) && !lightStop.CrossLane.TrafficInLane &&
                        !lightStop.RightTurn.TrafficInLane)
                    {
                        vehicle.Continue();
                        _vehiclesOnZ.Remove(vehicle);
                        break;
                    }

                    if (ReferenceEquals(lightStop.VehicleAtLight, vehicle) && lightStop.CrossLane.TrafficInLane &&
                        !lightStop.RightTurn.TrafficInLane)
                    {
                        vehiclesTurningRight++;
                        vehicle.Stop();
                    }
                    else
                    {
                        vehicle.Stop();
                    }
                }
            }
        }

        if (vehiclesTurningRight != 2)
        {
            return;
        }
        for (int i = _vehiclesOnZ.Count - 1; i >= 0; i--)
        {
            VehicleBehaviour vehicle = _vehiclesOnZ[i];
            vehicle.Continue();
            _vehiclesOnZ.Remove(vehicle);
        }
    }
コード例 #5
0
    // move traffic on X if the coast is clear
    private void MoveTrafficOnX()
    {
        int vehiclesTurningRight = 0;

        for (int i = _vehiclesOnX.Count - 1; i >= 0; i--)
        {
            VehicleBehaviour vehicle = _vehiclesOnX[i];
            if (vehicle.NextRoad == null && !vehicle.IsUnableToMove)
            {
                vehicle.SetNextRoad();
            }
            if (vehicle.NextRoad != null)
            {
                if (vehicle.NextRoad.GetComponent <WaypointPath>().GetCongestion() >
                    vehicle.NextRoad.GetComponent <WaypointPath>().CongestionThreshold)
                {
                    vehicle.SetNextRoad();
                }
            }
            if (vehicle.IsUnableToMove)
            {
                vehicle.Stop();
            }
            if (!vehicle.RightCross)
            {
                foreach (LightStopX lightStop in GetComponentsInChildren <LightStopX>())
                {
                    if (!ReferenceEquals(lightStop.VehicleAtLight, vehicle))
                    {
                        continue;
                    }
                    if ((vehicle.IsGoingStraightAtCross && !lightStop.StraightOn.TrafficInLane && !lightStop.Front.TrafficInLane) ||
                        (vehicle.LeftCross && !lightStop.LeftTurn.TrafficInLane && !lightStop.Front.TrafficInLane) ||
                        (vehicle.LeftJunctionJoin && !lightStop.LeftTurn.TrafficInLane) ||
                        (vehicle.RightJunctionJoin && !lightStop.RightTurn.TrafficInLane)
                        )
                    {
                        vehicle.Continue();
                        _vehiclesOnX.Remove(vehicle);
                    }
                    else
                    {
                        vehicle.Stop();
                    }
                }
            }
            else
            {
                foreach (LightStopX lightStop in GetComponentsInChildren <LightStopX>())
                {
                    if (ReferenceEquals(lightStop.VehicleAtLight, vehicle) && !lightStop.CrossLane.TrafficInLane &&
                        !lightStop.RightTurn.TrafficInLane)
                    {
                        vehicle.Continue();
                        _vehiclesOnX.Remove(vehicle);
                        break;
                    }
                    if (ReferenceEquals(lightStop.VehicleAtLight, vehicle) && lightStop.CrossLane.TrafficInLane &&
                        !lightStop.RightTurn.TrafficInLane)
                    {
                        vehiclesTurningRight++;
                        vehicle.Stop();
                    }
                    else
                    {
                        vehicle.Stop();
                    }
                }
            }
        }

        if (vehiclesTurningRight != 2)
        {
            return;
        }
        for (int i = _vehiclesOnX.Count - 1; i >= 0; i--)
        {
            VehicleBehaviour vehicle = _vehiclesOnX[i];
            vehicle.Continue();
            _vehiclesOnX.Remove(vehicle);
        }
    }