Traffic Lights Behaviour

Description

Controls the behavior of the lights inside a traffic light intersection.

Declaration

 public delegate void TrafficLightsBehaviour(TrafficLightsColor currentRoadColor, List<GameObject> redLightObjects, List<GameObject> yellowLightObjects, List<GameObject> greenLightObjects, string name);

Parameters

NameDescription

currentRoadColor

The current color that is on this road specified by the Traffic System .

redLightObjects

The list of the red lights objects assigned in editor.

yellowLightObjects

The list of the yellow lights objects assigned in editor.

greenLightObjects

The list of the green lights objects assigned in editor.

name

The name of the intersection.

Set Method

public static void SetTrafficLightsBehaviour(TrafficLightsBehaviour trafficLightsBehaviourDelegate)

Example

using Gley.TrafficSystem;
using System.Collections.Generic;
using UnityEngine;

public class Test : MonoBehaviour
{
    private void Start()
    {
        Delegates.SetTrafficLightsBehaviour(MyTrafficLightBehaviour);
    }

    void MyTrafficLightBehaviour(TrafficLightsColor currentRoadColor, List<GameObject> redLightObjects, List<GameObject> yellowLightObjects, List<GameObject> greenLightObjects, string name)
    {
        switch (currentRoadColor)
        {
            case TrafficLightsColor.Red:
                //color is red -> show red lights
                break;
            case TrafficLightsColor.Green:
                //color is green -> show green lights
                break;
            case TrafficLightsColor.YellowGreen:
                //color is yellow and before was green -> show yellow lights
                break;
            case TrafficLightsColor.YellowRed:
                //color is yellow and before was red -> show yellow lights
                break;
        }
    }
}

Default delegate implementation can be found inside DefaultDelegates.cs

Last updated