// this implements the Update method of MonoBehaviour public void Update() { //Log.Warning("CustomRoadAI: Update called"); var currentFrameIndex = Singleton <SimulationManager> .instance.m_currentFrameIndex >> 6; if (_lastFrame < currentFrameIndex) { _lastFrame = currentFrameIndex; if (TrafficLightTool.getToolMode() != ToolMode.AddPrioritySigns) { TrafficPriority.housekeeping(); } } try { foreach (KeyValuePair <ushort, TrafficLightSimulation> e in TrafficPriority.LightSimByNodeId) { var nodeSim = e.Value; nodeSim.SimulationStep(); } } catch (Exception) { // TODO the dictionary was modified (probably a segment connected to a traffic light was changed/removed). rework this } }
public void CustomNodeSimulationStep(ushort nodeId, ref NetNode data) { if (simStartFrame == 0) { simStartFrame = Singleton <SimulationManager> .instance.m_currentFrameIndex; } try { if (TrafficLightTool.getToolMode() != ToolMode.AddPrioritySigns) { try { TrafficPriority.nodeHousekeeping(nodeId); } catch (Exception e) { Log.Error($"Error occured while housekeeping node {nodeId}: " + e.ToString()); } } TrafficPriority.TrafficLightSimulationStep(); var nodeSim = TrafficLightSimulation.GetNodeSimulation(nodeId); if (nodeSim == null || !nodeSim.IsSimulationActive()) { OriginalSimulationStep(nodeId, ref data); } } catch (Exception e) { Log.Warning($"CustomNodeSimulationStep: An error occurred: {e.ToString()}"); } }
private void clickSwitchTraffic(UIComponent component, UIMouseEventParameter eventParam) { if (TrafficLightTool.getToolMode() != ToolMode.SwitchTrafficLight) { _buttonSwitchTraffic.focusedBgSprite = "ButtonMenuFocused"; TrafficLightTool.SetToolMode(ToolMode.SwitchTrafficLight); } else { _buttonSwitchTraffic.focusedBgSprite = "ButtonMenu"; TrafficLightTool.SetToolMode(ToolMode.None); } }
public void CustomSimulationStep(ushort nodeId, ref NetNode data) { if (TrafficLightTool.getToolMode() != ToolMode.AddPrioritySigns) { TrafficPriority.housekeeping(); } var nodeSim = TrafficPriority.GetNodeSimulation(nodeId); if (nodeSim != null && nodeSim.FlagTimedTrafficLights && nodeSim.TimedTrafficLightsActive) { nodeSim.SimulationStep(); } else if (nodeSim == null || (nodeSim.FlagTimedTrafficLights && !nodeSim.TimedTrafficLightsActive)) { OriginalSimulationStep(nodeId, ref data); } }