private void UpdatePedestrianLights(GameObject[] array, int state)
 {
     foreach (GameObject light in array)
     {
         PedestrianLight controller = light.GetComponent <PedestrianLight>();
         controller.setState(state);
     }
 }
예제 #2
0
        public TrafficLightModel()
        {
            ChangeStateCommand = new ToggleStateCommand();

            _gpio           = GpioController.GetDefault();
            CarTrafficLight = new CarTrafficLight(1, TrafficState.GO, _gpio, 5, 6, 13);

            PedestrianTrafficLight = new PedestrianLight(2, TrafficState.STOP, _gpio, 17, 27, 22);
        }
        private void CreateLights()
        {
            foreach (var id in _trafficLightIds)
            {
                if (id > 100 && id <= 110)
                {
                    var carLight = new CarLight(id);
                    CarLights.Add(carLight);
                }
                else if (id == 201)
                {
                    BusLight = new BusLight(id);
                }
                else if (id > 300 && id <= 305)
                {
                    var bicycleLight = new BicycleLight(id);
                    BicycleLights.Add(bicycleLight);
                }
                else if (id > 400 && id <= 412)
                {
                    var pedestrianLight = new PedestrianLight(id);
                    PedestrianLights.Add(pedestrianLight);
                }
                else if (id > 500 && id <= 502)
                {
                    var trainLight = new TrainLight(id);
                    TrainLights.Add(trainLight);
                }
                else if (id == 601)
                {
                    CrossingBarrier = new CrossingBarrier(id);
                }
            }

            Lights.AddRange(CarLights);
            Lights.Add(BusLight);
            Lights.AddRange(BicycleLights);
            Lights.AddRange(PedestrianLights);
            Lights.AddRange(TrainLights);
            Lights.Add(CrossingBarrier);
        }
    void FixedUpdate()
    {
        RaycastHit hit;
        Vector3    fwd = transform.TransformDirection(Vector3.forward);

        sensorOrigin  = transform.position;
        sensorOrigin += transform.forward * sensorOffset.z;
        sensorOrigin += transform.up * sensorOffset.y;

        if (Physics.Raycast(sensorOrigin, fwd, out hit, 2f))
        {
            if (hit.collider.gameObject.CompareTag("TLSPC"))
            {
                GameObject      collisionObject       = hit.collider.gameObject;
                GameObject      collisionObjectParent = collisionObject.transform.parent.gameObject;
                PedestrianLight light        = collisionObjectParent.GetComponent <PedestrianLight>();
                int             trafficState = light.getState();

                if (trafficState == 1)
                {
                    Debug.DrawLine(sensorOrigin, hit.point);
                    anim.SetBool("walking", false);
                    agent.isStopped        = true;
                    pedestrianStateChanged = true;
                }
            }

            if (hit.collider.gameObject.CompareTag("AICar"))
            {
                Debug.DrawLine(sensorOrigin, hit.point);
                anim.SetBool("walking", false);
                agent.isStopped        = true;
                pedestrianStateChanged = true;
            }

            if (hit.collider.gameObject.CompareTag("AIPedestrian"))
            {
                Debug.DrawLine(sensorOrigin, hit.point);
                anim.SetBool("walking", false);
                agent.isStopped        = true;
                pedestrianStateChanged = true;
            }
        }

        //if (Physics.Raycast(sensorOrigin, Quaternion.AngleAxis(frontSensorAngle, transform.up) * transform.forward, out hit, 2f))
        //{
        //    if (hit.collider.gameObject.CompareTag("TLSPC"))
        //    {
        //        GameObject collisionObject = hit.collider.gameObject;
        //        GameObject collisionObjectParent = collisionObject.transform.parent.gameObject;
        //        PedestrianLight light = collisionObjectParent.GetComponent<PedestrianLight>();
        //        int trafficState = light.getState();

        //        if (trafficState == 1)
        //        {
        //            Debug.DrawLine(sensorOrigin, hit.point);
        //            anim.SetBool("walking", false);
        //            agent.isStopped = true;
        //            pedestrianStateChanged = true;
        //        }
        //    }
        //}

        //if (Physics.Raycast(sensorOrigin, Quaternion.AngleAxis(-frontSensorAngle, transform.up) * transform.forward, out hit, 2f))
        //{
        //    if (hit.collider.gameObject.CompareTag("TLSPC"))
        //    {
        //        GameObject collisionObject = hit.collider.gameObject;
        //        GameObject collisionObjectParent = collisionObject.transform.parent.gameObject;
        //        PedestrianLight light = collisionObjectParent.GetComponent<PedestrianLight>();
        //        int trafficState = light.getState();

        //        if (trafficState == 1)
        //        {
        //            Debug.DrawLine(sensorOrigin, hit.point);
        //            anim.SetBool("walking", false);
        //            agent.isStopped = true;
        //            pedestrianStateChanged = true;
        //        }
        //    }
        //}

        if (!pedestrianStateChanged && agent.isStopped)
        {
            agent.isStopped = false;
            anim.SetBool("walking", true);
        }

        if (!agent.pathPending && agent.remainingDistance < 0.5f && !pedestrianStateChanged)
        {
            GotoNextPoint();
        }

        pedestrianStateChanged = false;
    }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UpperZebra"/> class.
 /// </summary>
 /// <param name="intersection">The intersection where the <see cref="UpperZebra"/> is.</param>
 /// <param name="pedestrianLight">The <see cref="PedestrianLight"/> for which the <see cref="UpperZebra"/> is 
 /// assigned to.</param>
 public UpperZebra(BaseIntersection intersection, PedestrianLight pedestrianLight) :
     base(intersection, pedestrianLight)
 {
 }