public override void OnInspectorGUI()
        {
            VehicleBehaviour vehicleBehaviour = (VehicleBehaviour)target;

            this.serializedObject.Update();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(vehicleModel);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(physicsSphere);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(vehicleBody);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(vehicleType);
            vehicleBehaviour.VehicleWheelCount = (VehicleType)vehicleType.enumValueIndex;
            EditorGUILayout.EndHorizontal();

            if (vehicleType.enumValueIndex == 0)
            {
                DisplayTwoWheels();
                DisplayFourWheels();
            }
            else if (vehicleType.enumValueIndex == 1)
            {
                DisplayTwoWheels();
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(vehicleSettings);
            EditorGUILayout.EndHorizontal();

            serializedObject.ApplyModifiedProperties();

            if (GUILayout.Button("Update Vehicle Settings", GUILayout.MinHeight(100), GUILayout.Height(50)))
            {
                vehicleBehaviour.SetVehicleSettings();
            }
        }
Example #2
0
 // stop traffic on X but allow right crossing cars to pass
 // if they have been waiting
 private void StopTrafficOnX()
 {
     if (GetComponentInChildren <TrafficLightControl>().GetAllRed() && GetComponentInChildren <TrafficLightControl>().PreviousLightGreenX)
     {
         for (int i = _vehiclesOnX.Count - 1; i >= 0; i--)
         {
             VehicleBehaviour vehicle = _vehiclesOnX[i];
             if (!vehicle.RightCross)
             {
                 continue;
             }
             vehicle.Continue();
             _vehiclesOnX.Remove(vehicle);
         }
     }
     foreach (VehicleBehaviour vehicle in _vehiclesOnX)
     {
         vehicle.Stop();
     }
 }
 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;
 }
Example #4
0
    public void SpawnNewPath()
    {
        if (m_CurrentIndex >= paths.Length)
        {
            return;
        }


        VehicleBehaviour vehicle = Instantiate(paths[m_CurrentIndex].spawnObject, paths[m_CurrentIndex].spawnTransform.position, paths[m_CurrentIndex].spawnTransform.rotation).GetComponent <VehicleBehaviour>();


        vehicle.destinationCollider = paths[m_CurrentIndex].destination;


        vehicles.Add(vehicle);

        virtualMainCamera.Follow = vehicle.transform;


        PlayBackOtherVehicles();
    }
    private void OnTriggerExit(Collider other)
    {
        if (!Handler.IsSomethingOnFire)
        {
            return;
        }
        if (other.gameObject.GetComponent <CarBackCollider>() == null)
        {
            return;
        }
        VehicleBehaviour vehicle = other.gameObject.GetComponentInParent <VehicleBehaviour>();

        if (vehicle == null)
        {
            return;
        }
        if (vehicle.CompareTag("firebrigade"))
        {
            _parent._speedConstant = RegularSpeed;
        }
    }
        private void GetWheelTransforms(VehicleBehaviour vehicleBehaviour)
        {
            wheelTransforms = new List <Transform>();

            if (vehicleBehaviour.BackLeftWheel != null)
            {
                wheelTransforms.Add(vehicleBehaviour.BackLeftWheel);
            }
            if (vehicleBehaviour.BackRightWheel != null)
            {
                wheelTransforms.Add(vehicleBehaviour.BackRightWheel);
            }
            if (vehicleBehaviour.FrontLeftWheel != null)
            {
                wheelTransforms.Add(vehicleBehaviour.FrontLeftWheel);
            }
            if (vehicleBehaviour.FrontRightWheel != null)
            {
                wheelTransforms.Add(vehicleBehaviour.FrontRightWheel);
            }
        }
Example #7
0
    private void OnTriggerEnter(Collider other)
    {
        if (!Handler.IsSomethingOnFire)
        {
            return;
        }
        if (other.gameObject.GetComponent <CarFrontCollider>() == null)
        {
            return;
        }
        VehicleBehaviour vehicle = other.gameObject.GetComponentInParent <VehicleBehaviour>();

        if (vehicle == null)
        {
            return;
        }
        if (Handler.Path.Contains(vehicle._currentRoad.GetComponent <WaypointPath>()))
        {
            return;
        }
        if (vehicle._isBraking)
        {
            return;
        }
        if (vehicle.IsGoingStraightAtJunction || vehicle.RightJunctionCrossing ||
            vehicle.RightJunctionJoin || vehicle.LeftJunctionJoin ||
            vehicle.LeftJunctionLeave || vehicle.LeftCross || vehicle.RightCross ||
            vehicle.IsGoingStraightAtCross)
        {
            return;
        }
        vehicle.EmergencyBrake       = true;
        vehicle._brakeTorqueConstant = vehicle.MaxBrakeTorque;
        foreach (JunctionLane lane in vehicle.JunctionLanes)
        {
            lane.TrafficInLane = false;
        }
    }
Example #8
0
    private void OnTriggerExit(Collider other)
    {
        if (other.gameObject.GetComponent <Siren>() != null)
        {
            return;
        }
        if (other.gameObject.GetComponent <CarFrontCollider>() != null)
        {
            return;
        }
        if (other.gameObject.GetComponent <CarBackCollider>() != null)
        {
            return;
        }
        VehicleBehaviour vehicle = other.gameObject.GetComponentInParent <VehicleBehaviour>();

        if (vehicle == null)
        {
            return;
        }
        _vehiclesInLane.Remove(vehicle);
        TrafficInLane = _vehiclesInLane.Count > 0;
        vehicle.CrossLanes.Remove(this);
    }
Example #9
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.GetComponent <Siren>() != null)
        {
            return;
        }
        if (other.gameObject.GetComponent <CarFrontCollider>() != null)
        {
            return;
        }
        if (other.gameObject.GetComponent <CarBackCollider>() != null)
        {
            return;
        }
        VehicleBehaviour vehicle = other.gameObject.GetComponentInParent <VehicleBehaviour>();

        if (vehicle == null)
        {
            return;
        }
        TrafficInLane = true;
        _vehiclesInLane.Add(vehicle);
        vehicle.CrossLanes.Add(this);
    }
    // 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);
                }
            }
        }
    }
Example #11
0
 private void Awake()
 {
     _parent = GetComponentInParent <VehicleBehaviour>();
 }
Example #12
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);
        }
    }
Example #13
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);
        }
    }
 private void Awake()
 {
     _parent      = GetComponentInParent <VehicleBehaviour>();
     RegularSpeed = _parent.MaxSpeed;
 }
Example #15
0
    protected void Evasion(VehicleBehaviour quarry)
    {
        Vector2 target = EstimateFuturePosition(quarry);

        Flee(target);
    }
Example #16
0
    protected void Pursuit(VehicleBehaviour quarry)
    {
        Vector2 target = EstimateFuturePosition(quarry);

        Seek(target);
    }