示例#1
0
        void TriggerStop(GameObject _vehicle)
        {
            VehicleAI vehicleAI = _vehicle.GetComponent <VehicleAI>();

            //Depending on the waypoint threshold, the car can be either on the target segment or on the past segment
            int vehicleSegment = vehicleAI.GetSegmentVehicleIsIn();

            if (!IsPrioritySegment(vehicleSegment))
            {
                if (vehiclesQueue.Count > 0 || vehiclesInIntersection.Count > 0)
                {
                    vehicleAI.vehicleStatus = Status.STOP;
                    vehiclesQueue.Add(_vehicle);
                }
                else
                {
                    vehiclesInIntersection.Add(_vehicle);
                    vehicleAI.vehicleStatus = Status.SLOW_DOWN;
                }
            }
            else
            {
                vehicleAI.vehicleStatus = Status.SLOW_DOWN;
                vehiclesInIntersection.Add(_vehicle);
            }
        }
示例#2
0
        private static void SetupVehicle()
        {
            EditorHelper.SetUndoGroup("Setup Vehicle");

            GameObject selected = Selection.activeGameObject;

            //Create raycast anchor
            GameObject anchor = EditorHelper.CreateGameObject("Raycast Anchor", selected.transform);

            //Add AI scripts
            VehicleAI  veAi       = EditorHelper.AddComponent <VehicleAI>(selected);
            WheelDrive wheelDrive = EditorHelper.AddComponent <WheelDrive>(selected);

            TrafficSystem ts = GameObject.FindObjectOfType <TrafficSystem>();

            //Configure the vehicle AI script with created objects
            anchor.transform.localPosition = Vector3.zero;
            anchor.transform.localRotation = Quaternion.Euler(Vector3.zero);
            veAi.raycastAnchor             = anchor.transform;

            if (ts != null)
            {
                veAi.trafficSystem = ts;
            }

            //Create layer AutonomousVehicle if it doesn't exist
            EditorHelper.CreateLayer("AutonomousVehicle");

            //Set the tag and layer name
            selected.tag = "AutonomousVehicle";
            EditorHelper.SetLayer(selected, LayerMask.NameToLayer("AutonomousVehicle"), true);
        }
示例#3
0
        void TriggerLight(GameObject _vehicle)
        {
            VehicleAI vehicleAI      = _vehicle.GetComponent <VehicleAI>();
            int       vehicleSegment = vehicleAI.GetSegmentVehicleIsIn();

            if (IsRedLightSegment(vehicleSegment))
            {
                vehicleAI.vehicleStatus = Status.STOP;
                vehiclesQueue.Add(_vehicle);
            }
            else
            {
                vehicleAI.vehicleStatus = Status.GO;
            }
        }