void Awake() { TrafficSystem = GetComponent <TrafficSystem>(); // Subscribe to segment and road lattice events. MapsService mapsService = GetComponent <MapsService>(); mapsService.Events.SegmentEvents.DidCreate.AddListener(OnSegmentCreated); mapsService.Events.RoadLatticeEvents.DidModify.AddListener(OnRoadLatticeModified); }
/// <summary> /// Initializes the vehicle. /// </summary> /// <param name="trafficSystem">The traffic system.</param> /// <param name="startNode">The node the vehicle should start at.</param> public void Initialize(TrafficSystem trafficSystem, RoadLatticeNode startNode) { TrafficSystem = trafficSystem; // Find a target node from the start node. RoadLatticeNode targetNode = FindNextTarget(startNode, null); CurrentNodeLocationUID = startNode.LocationUID; TargetNodeLocationUID = targetNode.LocationUID; // Set the vehicle's position and rotation. Vector2 heading = (targetNode.Location - startNode.Location).normalized; transform.position = new Vector3(startNode.Location.x, 0, startNode.Location.y) + new Vector3(-heading.y, 0, heading.x) * DistanceFromRoadCenter; transform.forward = new Vector3(heading.x, 0, heading.y); }