예제 #1
0
    /// <summary>
    /// Sets the intersection to a new state. (sets appropriate waypoint labels and changes lights).
    /// </summary>
    /// <param name="newState">Parameter which sets this intersection either to the new state.</param>
    private void switchState(int newState)
    {
        PointDescriptor point1Descriptor = transform.Find("semaphore1").Find("point1").GetComponent <PointDescriptor>();
        PointDescriptor point2Descriptor = transform.Find("semaphore2").Find("point2").GetComponent <PointDescriptor>();
        PointDescriptor point3Descriptor = transform.Find("semaphore3").Find("point3").GetComponent <PointDescriptor>();
        PointDescriptor point4Descriptor = transform.Find("semaphore4").Find("point4").GetComponent <PointDescriptor>();

        switch (newState)
        {
        case VERTICAL:
        case VERTICAL_TO_HORIZONTAL:
            point1Descriptor.setLabel(POINT_STATE1);
            point2Descriptor.setLabel(POINT_STATE2);
            point3Descriptor.setLabel(POINT_STATE2);
            point4Descriptor.setLabel(POINT_STATE1);
            break;

        case HORIZONTAL:
        case HORIZONTAL_TO_VERTICAL:
            point1Descriptor.setLabel(POINT_STATE1);
            point2Descriptor.setLabel(POINT_STATE1);
            point3Descriptor.setLabel(POINT_STATE2);
            point4Descriptor.setLabel(POINT_STATE2);
            break;
        }
        currentState = newState;
        changeLights(currentState);
        manageDecelerationPoints(currentState);
    }
예제 #2
0
    /// <summary>
    /// Changes label states of points whose name begins with "carDecelerate". This allows the cars
    /// to move when the light is green and orders them to stop when it is red.
    /// </summary>
    /// <param name="newState">New intersection state</param>
    private void manageDecelerationPoints(int newState)
    {
        PointDescriptor carDecelerate1Descriptor = transform.Find("semaphore1").Find("carDecelerate1").GetComponent <PointDescriptor>();
        PointDescriptor carDecelerate2Descriptor = transform.Find("semaphore2").Find("carDecelerate2").GetComponent <PointDescriptor>();
        PointDescriptor carDecelerate3Descriptor = transform.Find("semaphore3").Find("carDecelerate3").GetComponent <PointDescriptor>();
        PointDescriptor carDecelerate4Descriptor = transform.Find("semaphore4").Find("carDecelerate4").GetComponent <PointDescriptor>();

        switch (newState)
        {
        case VERTICAL:
            carDecelerate1Descriptor.setLabel(POINT_STATE1);
            carDecelerate2Descriptor.setLabel(POINT_STATE2);
            carDecelerate3Descriptor.setLabel(POINT_STATE1);
            carDecelerate4Descriptor.setLabel(POINT_STATE2);
            break;

        case HORIZONTAL:
            carDecelerate1Descriptor.setLabel(POINT_STATE2);
            carDecelerate2Descriptor.setLabel(POINT_STATE1);
            carDecelerate3Descriptor.setLabel(POINT_STATE2);
            carDecelerate4Descriptor.setLabel(POINT_STATE1);
            break;

        default:
            carDecelerate1Descriptor.setLabel(POINT_STATE2);
            carDecelerate2Descriptor.setLabel(POINT_STATE2);
            carDecelerate3Descriptor.setLabel(POINT_STATE2);
            carDecelerate4Descriptor.setLabel(POINT_STATE2);
            break;
        }
    }
예제 #3
0
    /// <summary>
    /// Sets labels of auxiliary waypoints to 1. This means that the cars can reach them only if the
    /// traffic light is green.
    /// </summary>
    private void manageAuxiliaryPoints()
    {
        PointDescriptor carExit1Point = transform.Find("AuxiliaryWaypoints").Find("carExit1").GetComponent <PointDescriptor>();
        PointDescriptor carExit2Point = transform.Find("AuxiliaryWaypoints").Find("carExit2").GetComponent <PointDescriptor>();
        PointDescriptor carExit4Point = transform.Find("AuxiliaryWaypoints").Find("carExit4").GetComponent <PointDescriptor>();

        PointDescriptor carRight1Point = transform.Find("semaphore1").Find("carRight1").GetComponent <PointDescriptor>();
        PointDescriptor carRight2Point = transform.Find("semaphore2").Find("carRight2").GetComponent <PointDescriptor>();

        carExit1Point.setLabel(POINT_STATE1);
        carExit2Point.setLabel(POINT_STATE1);
        carExit4Point.setLabel(POINT_STATE1);

        carRight1Point.setLabel(POINT_STATE1);
        carRight2Point.setLabel(POINT_STATE1);
    }