public void OnUpdate(NodeGeometry nodeGeometry) { #if DEBUG Log._Debug($"TrafficLightSimulation: OnUpdate @ node {NodeId} ({nodeGeometry.NodeId})"); #endif if (!Flags.mayHaveTrafficLight(NodeId)) { Log.Warning($"Housekeeping: Node {NodeId} has traffic light simulation but must not have a traffic light!"); TrafficLightSimulationManager.Instance().RemoveNodeFromSimulation(NodeId, false, true); } if (!IsManualLight() && !IsTimedLight()) { return; } if (!nodeGeometry.IsValid()) { // node has become invalid. Remove manual/timed traffic light and destroy custom lights TrafficLightSimulationManager.Instance().RemoveNodeFromSimulation(NodeId, false, false); return; } CustomTrafficLightsManager customTrafficLightsManager = CustomTrafficLightsManager.Instance(); for (var s = 0; s < 8; s++) { var segmentId = Singleton <NetManager> .instance.m_nodes.m_buffer[NodeId].GetSegment(s); if (segmentId == 0) { continue; } #if DEBUG Log._Debug($"TrafficLightSimulation: OnUpdate @ node {NodeId}: Adding live traffic lights to segment {segmentId}"); #endif // add custom lights if (!customTrafficLightsManager.IsSegmentLight(NodeId, segmentId)) { customTrafficLightsManager.AddSegmentLights(NodeId, segmentId); } // housekeep timed light customTrafficLightsManager.GetSegmentLights(NodeId, segmentId).housekeeping(true); } // ensure there is a physical traffic light Flags.setNodeTrafficLight(NodeId, true); TimedLight?.handleNewSegments(); TimedLight?.housekeeping(); }
private void destroyLiveSegments() { CustomTrafficLightsManager customTrafficLightsManager = CustomTrafficLightsManager.Instance(); for (var s = 0; s < 8; s++) { var segmentId = Singleton <NetManager> .instance.m_nodes.m_buffer[NodeId].GetSegment(s); if (segmentId == 0) { continue; } if (customTrafficLightsManager.IsSegmentLight(NodeId, segmentId)) { customTrafficLightsManager.RemoveSegmentLight(NodeId, segmentId); } } }
private void setupLiveSegments() { CustomTrafficLightsManager customTrafficLightsManager = CustomTrafficLightsManager.Instance(); for (var s = 0; s < 8; s++) { var segmentId = Singleton <NetManager> .instance.m_nodes.m_buffer[NodeId].GetSegment(s); if (segmentId == 0) { continue; } //SegmentGeometry.Get(segmentId)?.Recalculate(true, true); if (!customTrafficLightsManager.IsSegmentLight(NodeId, segmentId)) { customTrafficLightsManager.AddSegmentLights(NodeId, segmentId); } } }
private void RenderManualNodeOverlays(RenderManager.CameraInfo cameraInfo) { var nodeSimulation = TrafficLightSimulationManager.Instance().GetNodeSimulation(SelectedNodeId); CustomTrafficLightsManager customTrafficLightsManager = CustomTrafficLightsManager.Instance(); for (var i = 0; i < 8; i++) { var colorGray = new Color(0.25f, 0.25f, 0.25f, 0.25f); ushort segmentId = Singleton <NetManager> .instance.m_nodes.m_buffer[SelectedNodeId].GetSegment(i); if (segmentId == 0 || (nodeSimulation != null && customTrafficLightsManager.IsSegmentLight(SelectedNodeId, segmentId))) { continue; } var position = CalculateNodePositionForSegment(Singleton <NetManager> .instance.m_nodes.m_buffer[SelectedNodeId], segmentId); var width = _hoveredButton[0] == segmentId ? 11.25f : 10f; MainTool.DrawOverlayCircle(cameraInfo, colorGray, position, width, segmentId != _hoveredButton[0]); } }
public override void OnToolGUI(Event e) { var hoveredSegment = false; if (SelectedNodeId != 0) { CustomTrafficLightsManager customTrafficLightsManager = CustomTrafficLightsManager.Instance(); TrafficLightSimulationManager tlsMan = TrafficLightSimulationManager.Instance(); var nodeSimulation = tlsMan.GetNodeSimulation(SelectedNodeId); nodeSimulation.housekeeping(); /*if (Singleton<NetManager>.instance.m_nodes.m_buffer[SelectedNode].CountSegments() == 2) { * _guiManualTrafficLightsCrosswalk(ref Singleton<NetManager>.instance.m_nodes.m_buffer[SelectedNode]); * return; * }*/// TODO check for (var i = 0; i < 8; i++) { var segmentId = Singleton <NetManager> .instance.m_nodes.m_buffer[SelectedNodeId].GetSegment(i); if (segmentId == 0 || nodeSimulation == null || !customTrafficLightsManager.IsSegmentLight(SelectedNodeId, segmentId)) { continue; } var position = CalculateNodePositionForSegment(Singleton <NetManager> .instance.m_nodes.m_buffer[SelectedNodeId], ref Singleton <NetManager> .instance.m_segments.m_buffer[segmentId]); var segmentLights = customTrafficLightsManager.GetSegmentLights(SelectedNodeId, segmentId); var screenPos = Camera.main.WorldToScreenPoint(position); screenPos.y = Screen.height - screenPos.y; if (screenPos.z < 0) { continue; } var diff = position - Camera.main.transform.position; var zoom = 1.0f / diff.magnitude * 100f; // original / 2.5 var lightWidth = 41f * zoom; var lightHeight = 97f * zoom; var pedestrianWidth = 36f * zoom; var pedestrianHeight = 61f * zoom; // SWITCH MODE BUTTON var modeWidth = 41f * zoom; var modeHeight = 38f * zoom; var guiColor = GUI.color; if (segmentLights.PedestrianLightState != null) { // pedestrian light // SWITCH MANUAL PEDESTRIAN LIGHT BUTTON hoveredSegment = RenderManualPedestrianLightSwitch(zoom, segmentId, screenPos, lightWidth, segmentLights, hoveredSegment); // SWITCH PEDESTRIAN LIGHT guiColor.a = _hoveredButton[0] == segmentId && _hoveredButton[1] == 2 && segmentLights.ManualPedestrianMode ? 0.92f : 0.6f; GUI.color = guiColor; var myRect3 = new Rect(screenPos.x - pedestrianWidth / 2 - lightWidth + 5f * zoom, screenPos.y - pedestrianHeight / 2 + 22f * zoom, pedestrianWidth, pedestrianHeight); switch (segmentLights.PedestrianLightState) { case RoadBaseAI.TrafficLightState.Green: GUI.DrawTexture(myRect3, TrafficLightToolTextureResources.PedestrianGreenLightTexture2D); break; case RoadBaseAI.TrafficLightState.Red: default: GUI.DrawTexture(myRect3, TrafficLightToolTextureResources.PedestrianRedLightTexture2D); break; } hoveredSegment = IsPedestrianLightHovered(myRect3, segmentId, hoveredSegment, segmentLights); } int lightOffset = -1; foreach (ExtVehicleType vehicleType in segmentLights.VehicleTypes) { ++lightOffset; CustomSegmentLight segmentLight = segmentLights.GetCustomLight(vehicleType); Vector3 offsetScreenPos = screenPos; offsetScreenPos.y -= (lightHeight + 10f * zoom) * lightOffset; SetAlpha(segmentId, -1); var myRect1 = new Rect(offsetScreenPos.x - modeWidth / 2, offsetScreenPos.y - modeHeight / 2 + modeHeight - 7f * zoom, modeWidth, modeHeight); GUI.DrawTexture(myRect1, TrafficLightToolTextureResources.LightModeTexture2D); hoveredSegment = GetHoveredSegment(myRect1, segmentId, hoveredSegment, segmentLight); // COUNTER hoveredSegment = RenderCounter(segmentId, offsetScreenPos, modeWidth, modeHeight, zoom, segmentLights, hoveredSegment); if (lightOffset > 0) { // Info sign var infoWidth = 56.125f * zoom; var infoHeight = 51.375f * zoom; int numInfos = 0; for (int k = 0; k < TrafficManagerTool.InfoSignsToDisplay.Length; ++k) { if ((TrafficManagerTool.InfoSignsToDisplay[k] & vehicleType) == ExtVehicleType.None) { continue; } var infoRect = new Rect(offsetScreenPos.x + modeWidth / 2f + 7f * zoom * (float)(numInfos + 1) + infoWidth * (float)numInfos, offsetScreenPos.y - infoHeight / 2f, infoWidth, infoHeight); guiColor.a = 0.6f; GUI.DrawTexture(infoRect, TrafficLightToolTextureResources.VehicleInfoSignTextures[TrafficManagerTool.InfoSignsToDisplay[k]]); ++numInfos; } } SegmentGeometry geometry = SegmentGeometry.Get(segmentId); bool startNode = geometry.StartNodeId() == SelectedNodeId; if (geometry.IsOutgoingOneWay(startNode)) { continue; } var hasLeftSegment = geometry.HasLeftSegment(startNode); var hasForwardSegment = geometry.HasStraightSegment(startNode); var hasRightSegment = geometry.HasRightSegment(startNode); switch (segmentLight.CurrentMode) { case CustomSegmentLight.Mode.Simple: hoveredSegment = SimpleManualSegmentLightMode(segmentId, offsetScreenPos, lightWidth, pedestrianWidth, zoom, lightHeight, segmentLight, hoveredSegment); break; case CustomSegmentLight.Mode.SingleLeft: hoveredSegment = LeftForwardRManualSegmentLightMode(hasLeftSegment, segmentId, offsetScreenPos, lightWidth, pedestrianWidth, zoom, lightHeight, segmentLight, hoveredSegment, hasForwardSegment, hasRightSegment); break; case CustomSegmentLight.Mode.SingleRight: hoveredSegment = RightForwardLSegmentLightMode(segmentId, offsetScreenPos, lightWidth, pedestrianWidth, zoom, lightHeight, hasForwardSegment, hasLeftSegment, segmentLight, hasRightSegment, hoveredSegment); break; default: // left arrow light if (hasLeftSegment) { hoveredSegment = LeftArrowLightMode(segmentId, lightWidth, hasRightSegment, hasForwardSegment, offsetScreenPos, pedestrianWidth, zoom, lightHeight, segmentLight, hoveredSegment); } // forward arrow light if (hasForwardSegment) { hoveredSegment = ForwardArrowLightMode(segmentId, lightWidth, hasRightSegment, offsetScreenPos, pedestrianWidth, zoom, lightHeight, segmentLight, hoveredSegment); } // right arrow light if (hasRightSegment) { hoveredSegment = RightArrowLightMode(segmentId, offsetScreenPos, lightWidth, pedestrianWidth, zoom, lightHeight, segmentLight, hoveredSegment); } break; } } } } if (hoveredSegment) { return; } _hoveredButton[0] = 0; _hoveredButton[1] = 0; }