TrafficOptions

Description

A properties class used to initialize the Traffic System

Declaration

 public class TrafficOptions

Members

NameDescription

minDistanceToAdd

Beyond the MinDistanceToAdd, vehicles will spawn even without any obstructions or buildings blocking the view.

distanceToRemove

This value represents the approximate distance from the player at which a vehicle is flagged to be removed from the scene.

masterVolume

Represents the proximity from the player within which the adjacent cells will be active.

useWaypointPriority

Enables the usage of priority waypoints.

greenLightTime

The master intersection green time, if set, will override the individual times set on each intersection.

yellowLightTime

The master intersection yellow time, if set, will override the individual times set on each intersection.

activeSquaresLevel

Represents the proximity from the player within which the adjacent cells will be active.

initialDensity

The number of vehicles that will be active from the start. Should be <= than maxNrOfVehicles.

lightsOn

If true, the vehicles will be instantiated with lights on by default.

disableWaypointsArea

Mark the waypoints in that area as disabled from the start. No vehicles will spawn there.

For more in-depth details of each member consult the Initializing Assetsection.

Example

Assign all the properties inside the inspector, create a TrafficOptions object, and add it to the Initialize method.

If an option is not set, the default value will be used. Only set the properties you want to change.

public Transform player;
public int nrOfVehicles = 1;
public VehiclePool vehiclePool;
public int activeSquareLevels = 1;
public float minDistanceToAdd = -1;
public float distanceToRemove = -1;
public float yellowLightTime = -1;
public float greenLightTime = -1;
public int initialActiveVehicles = -1;
public bool useWaypointPriority = false;
public bool lightsOn = false;
public Area disableWaypointsArea = default;

void Start()
{
    TrafficOptions options = new TrafficOptions()
    {
        activeSquaresLevel = activeSquareLevels,
        disableWaypointsArea = disableWaypointsArea,
        distanceToRemove = distanceToRemove,
        greenLightTime = greenLightTime,
        initialDensity = initialActiveVehicles,
        lightsOn = lightsOn,
        minDistanceToAdd = minDistanceToAdd,
        useWaypointPriority = useWaypointPriority,
        yellowLightTime = yellowLightTime,
    };

   
    API.Initialize(player, nrOfVehicles, vehiclePool, options);
}

Last updated