void Update()
    {
        // Wait until we have loaded a network
        if (!triggerAreasSet && junctionsParentObject.transform.childCount > 0)
        {
            junctions = new List <GameObject>(junctionsParentObject.transform.childCount);

            // Populate the list of roads with the child objects of Junctions
            foreach (Transform child in junctionsParentObject.transform)
            {
                // TODO: Do we want to filter the juctions at all? We may want to take out dead ends, for example
                junctions.Add(child.gameObject);
            }

            List <string[]> juncIncomingLaneIds = junctionScript.Junction_List.Select(j => j.IncomingLanes.Split(' ')).ToList();
            juncIncomingLaneIds.ForEach(j => Array.Sort(j));
            foreach (string trafficLightId in traciController.Client.TrafficLight.GetIdList().Content)
            {
                var trafficLight            = traciController.Client.TrafficLight;
                List <List <string> > links = trafficLight.GetControlledLinks(trafficLightId).Content.Links;
                List <string>         tlIncomingLaneList = new List <string>();
                foreach (var link in links)
                {
                    tlIncomingLaneList.Add(link[0]);
                }
                //string[] tlIncomingLaneIds = traciController.Client.TrafficLight.GetControlledLinks(trafficLightId).Content.Links.Select(l => l[0]).ToArray();
                string[] tlIncomingLaneIds = tlIncomingLaneList.ToArray();
                Array.Sort(tlIncomingLaneIds);
                Debug.Log(tlIncomingLaneIds);
                Debug.Log(tlIncomingLaneIds.Length);
                int junctionIdx = juncIncomingLaneIds.FindIndex(j => j.Any(l => tlIncomingLaneIds.Contains(l)));

                if (junctionIdx >= 0)
                {
                    junctionAndTrafficLightIds.Add(junctionScript.Junction_List[junctionIdx].Id, trafficLightId);
                }
            }

            // Set the trigger actions to the road bounds
            markerAction.AddTriggerAreas(junctions.Select(j => j.GetComponent <MeshRenderer>().bounds));

            triggerAreasSet = true;
        }
    }
コード例 #2
0
    void Update()
    {
        // Wait until we have loaded a network
        if (!triggerAreasSet && lanesParentObject.transform.childCount > 0)
        {
            lanes = new List <GameObject>(lanesParentObject.transform.childCount);

            // Populate the list of roads with the child objects of Edges
            foreach (Transform child in lanesParentObject.transform)
            {
                // Some of the children are roads (not lanes) - we only want the lanes
                if (edgeScript.RoadList.Any(r => r.Lanes.Any(l => l.Id == child.name)))
                {
                    lanes.Add(child.gameObject);
                }
            }

            // Set the trigger actions to the road bounds
            markerAction.AddTriggerAreas(lanes.Select(l => l.GetComponent <LineRenderer>().bounds));

            triggerAreasSet = true;
        }
    }