Exemple #1
0
        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()}");
            }
        }
Exemple #2
0
        // 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
            }
        }
Exemple #3
0
        internal void rebuildSegmentIds()
        {
            var node = TrafficLightTool.GetNetNode(nodeId);

            List <ushort> oldSegmentIds = new List <ushort>(segmentIds);

            maxSegmentLength = 0;
            segmentIds.Clear();
            for (var s = 0; s < 8; s++)
            {
                var segmentId = node.GetSegment(s);

                if (segmentId <= 0)
                {
                    continue;
                }

                float segLength = Singleton <NetManager> .instance.m_segments.m_buffer[segmentId].m_averageLength;
                if (segLength > maxSegmentLength)
                {
                    maxSegmentLength = segLength;
                }

                segmentIds.Add(segmentId);
                oldSegmentIds.Remove(segmentId);
            }

            foreach (var segmentId in oldSegmentIds)
            {
                segmentIds.Add(segmentId);
            }
        }
        public static bool HasForwardSegment(int segmentId, ushort nodeId, bool debug = false)
        {
            if (segmentId <= 0)
            {
                return(false);
            }

            var node = TrafficLightTool.GetNetNode(nodeId);

            for (var s = 0; s < 8; s++)
            {
                var segment = node.GetSegment(s);

                if (segment == 0 || segment == segmentId)
                {
                    continue;
                }
                if (IsRightSegment(segmentId, segment, nodeId) || IsLeftSegment(segmentId, segment, nodeId))
                {
                    continue;
                }

                if (debug)
                {
                    Log.Message("FORWARD: " + segment + " " + GetSegmentDir(segment, nodeId));
                }
                return(true);
            }

            return(false);
        }
Exemple #5
0
        private void clickChangeLanes(UIComponent component, UIMouseEventParameter eventParam)
        {
            if (_uistate != UIState.LaneChange)
            {
                _uistate = UIState.LaneChange;

                if (!LoadingExtension.PathfinderIncompatibility)
                {
                    buttonLaneChange.focusedBgSprite = "ButtonMenuFocused";
                }

                TrafficLightTool.setToolMode(TrafficLightTool.ToolMode.LaneChange);
            }
            else
            {
                _uistate = UIState.None;

                if (!LoadingExtension.PathfinderIncompatibility)
                {
                    buttonLaneChange.focusedBgSprite = "ButtonMenu";
                }

                TrafficLightTool.setToolMode(TrafficLightTool.ToolMode.None);
            }
        }
		public override void Start() {
			if (LoadingExtension.Instance == null) {
				Log.Error("UITrafficManager.Start(): LoadingExtension is null.");
				return;
			}
			TrafficLightTool = LoadingExtension.Instance.TrafficLightTool;

			backgroundSprite = "GenericPanel";
			color = new Color32(75, 75, 135, 255);
			width = Translation.getMenuWidth();
			height = LoadingExtension.IsPathManagerCompatible ? 390 : 230;
#if DEBUG
			height += 160;		
#endif
			relativePosition = new Vector3(85f, 80f);

			UILabel title = AddUIComponent<UILabel>();
			title.text = "Version 1.6.5";
			title.relativePosition = new Vector3(50.0f, 5.0f);

			int y = 30;
			_buttonSwitchTraffic = _createButton(Translation.GetString("Switch_traffic_lights"), y, clickSwitchTraffic);
			y += 40;
			_buttonPrioritySigns = _createButton(Translation.GetString("Add_priority_signs"), y, clickAddPrioritySigns);
			y += 40;
			_buttonManualControl = _createButton(Translation.GetString("Manual_traffic_lights"), y, clickManualControl);
			y += 40;
			_buttonTimedMain = _createButton(Translation.GetString("Timed_traffic_lights"), y, clickTimedAdd);
			y += 40;

			if (LoadingExtension.IsPathManagerCompatible) {
				_buttonLaneChange = _createButton(Translation.GetString("Change_lane_arrows"), y, clickChangeLanes);
				y += 40;

				_buttonSpeedLimits = _createButton(Translation.GetString("Speed_limits"), y, clickSpeedLimits);
				y += 40;

				_buttonVehicleRestrictions = _createButton(Translation.GetString("Vehicle_restrictions"), y, clickVehicleRestrictions);
				y += 40;
			}

			_buttonClearTraffic = _createButton(Translation.GetString("Clear_Traffic"), y, clickClearTraffic);
			y += 40;

			if (LoadingExtension.IsPathManagerCompatible) {
				_buttonToggleDespawn = _createButton(Options.enableDespawning ? Translation.GetString("Disable_despawning") : Translation.GetString("Enable_despawning"), y, ClickToggleDespawn);
				y += 40;
			}

#if DEBUG
			_goToField = CreateTextField("", y);
			y += 40;
			_goToSegmentButton = _createButton("Goto segment", y, clickGoToSegment);
			y += 40;
			_goToNodeButton = _createButton("Goto node", y, clickGoToNode);
			y += 40;
			_goToVehicleButton = _createButton("Goto vehicle", y, clickGoToVehicle);
			y += 40;
#endif
		}
Exemple #7
0
        public override void Start()
        {
            inited = true;

            trafficLightTool = LoadingExtension.Instance.TrafficLightTool;

            this.backgroundSprite = "GenericPanel";
            this.color            = new Color32(75, 75, 135, 255);
            this.width            = 250;
            this.height           = 350;
            this.relativePosition = new Vector3(10.48f, 80f);

            UILabel title = this.AddUIComponent <UILabel>();

            title.text             = "Traffic Manager";
            title.relativePosition = new Vector3(65.0f, 5.0f);

            buttonSwitchTraffic = _createButton("Switch traffic lights", new Vector3(35f, 30f), clickSwitchTraffic);
            buttonPrioritySigns = _createButton("Add priority signs", new Vector3(35f, 70f), clickAddPrioritySigns);
            buttonManualControl = _createButton("Manual traffic lights", new Vector3(35f, 110f), clickManualControl);
            buttonTimedMain     = _createButton("Timed traffic lights", new Vector3(35f, 150f), clickTimedAdd);
            buttonLaneChange    = _createButton("Change lanes", new Vector3(35f, 190f), clickChangeLanes);
            buttonCrosswalk     = _createButton("Add/Remove Crosswalk", new Vector3(35f, 230f), clickCrosswalk);
            buttonClearTraffic  = _createButton("Clear Traffic", new Vector3(35f, 270f), clickClearTraffic);
            buttonToggleDespawn = _createButton(LoadingExtension.Instance.despawnEnabled ? "Disable Despawning" : "Enable Despawning", new Vector3(35f, 310f), clickToggleDespawn);
        }
Exemple #8
0
 private void DestroyTool()
 {
     if (TrafficLightTool != null)
     {
         TrafficLightTool.Destroy(TrafficLightTool);
         TrafficLightTool = null;
     }
 }
Exemple #9
0
 public void HideTMPanel()
 {
     if (tmPanel != null)
     {
         tmPanel.isVisible = false;
     }
     UITrafficManager.uistate = UITrafficManager.UIState.None;
     TrafficLightTool.setToolMode(TrafficLightTool.ToolMode.None);
     LoadingExtension.Instance.SetToolMode(TrafficManagerMode.None);
 }
Exemple #10
0
        public void EnableTool()
        {
            if (TrafficLightTool == null)
            {
                TrafficLightTool = ToolsModifierControl.toolController.gameObject.GetComponent <TrafficLightTool>() ??
                                   ToolsModifierControl.toolController.gameObject.AddComponent <TrafficLightTool>();
            }

            ToolsModifierControl.toolController.CurrentTool = TrafficLightTool;
        }
Exemple #11
0
        private void DestroyTool()
        {
            if (TrafficLightTool != null)
            {
                ToolsModifierControl.toolController.CurrentTool = ToolsModifierControl.GetTool <DefaultTool>();
                ToolsModifierControl.SetTool <DefaultTool>();

                TrafficLightTool.Destroy(TrafficLightTool);
                TrafficLightTool = null;
            }
        }
        public override void Start()
        {
            TrafficLightTool = LoadingExtension.Instance.TrafficLightTool;
            //this makes the panel "visible", I don't know what sprites are available, but found this value to work
            backgroundSprite = "GenericPanel";
            color = new Color32(75, 75, 135, 255);
            width = 800;
            height = 400;
            relativePosition = new Vector3(10.48f, 80f);

            var l = AddUIComponent<UILabel>();
            l.text = "Timed Scripts";
            l.relativePosition = new Vector3(65.0f, 5.0f);
        }
Exemple #13
0
        public void EnableTool()
        {
            if (TrafficLightTool == null)
            {
                TrafficLightTool = ToolsModifierControl.toolController.gameObject.GetComponent <TrafficLightTool>() ??
                                   ToolsModifierControl.toolController.gameObject.AddComponent <TrafficLightTool>();

//                var laneTool = ToolsModifierControl.toolController.gameObject.GetComponent<CSL_Traffic.RoadCustomizerTool>() ??
//                    ToolsModifierControl.toolController.gameObject.AddComponent<CSL_Traffic.RoadCustomizerTool>();
            }

            ToolsModifierControl.toolController.CurrentTool = TrafficLightTool;
            ToolsModifierControl.SetTool <TrafficLightTool>();
        }
        public override void Start()
        {
            if (LoadingExtension.Instance == null)
            {
                Log.Error("UITrafficManager.Start(): LoadingExtension is null.");
                return;
            }
            TrafficLightTool = LoadingExtension.Instance.TrafficLightTool;

            backgroundSprite = "GenericPanel";
            color            = new Color32(75, 75, 135, 255);
            width            = 250;
            height           = LoadingExtension.IsPathManagerCompatible ? 350 : 270;
            relativePosition = new Vector3(10.48f, 80f);

            UILabel title = AddUIComponent <UILabel>();

            title.text             = "Version 1.3.12";
            title.relativePosition = new Vector3(65.0f, 5.0f);

            int y = 30;

            _buttonSwitchTraffic = _createButton("Switch traffic lights", new Vector3(35f, y), clickSwitchTraffic);
            y += 40;
            _buttonPrioritySigns = _createButton("Add priority signs", new Vector3(35f, y), clickAddPrioritySigns);
            y += 40;
            _buttonManualControl = _createButton("Manual traffic lights", new Vector3(35f, y), clickManualControl);
            y += 40;
            _buttonTimedMain = _createButton("Timed traffic lights", new Vector3(35f, y), clickTimedAdd);
            y += 40;

            if (LoadingExtension.IsPathManagerCompatible)
            {
                _buttonLaneChange = _createButton("Change lanes", new Vector3(35f, y), clickChangeLanes);
                y += 40;
                //buttonLaneRestrictions = _createButton("Road Restrictions", new Vector3(35f, 230f), clickLaneRestrictions);
            }

            _buttonCrosswalk = _createButton("Add/Remove Crosswalk", new Vector3(35f, y), clickCrosswalk);
            y += 40;
            _buttonClearTraffic = _createButton("Clear Traffic", new Vector3(35f, y), clickClearTraffic);
            y += 40;

            if (LoadingExtension.IsPathManagerCompatible)
            {
                _buttonToggleDespawn = _createButton(LoadingExtension.Instance.DespawnEnabled ? "Disable despawning" : "Enable despawning", new Vector3(35f, y), ClickToggleDespawn);
                y += 40;
            }
        }
Exemple #15
0
        public override void Start()
        {
            trafficLightTool = LoadingExtension.Instance.TrafficLightTool;
            //this makes the panel "visible", I don't know what sprites are available, but found this value to work
            this.backgroundSprite = "GenericPanel";
            this.color            = new Color32(75, 75, 135, 255);
            this.width            = 800;
            this.height           = 400;
            this.relativePosition = new Vector3(10.48f, 80f);

            UILabel l = this.AddUIComponent <UILabel>();

            l.text             = "Timed Scripts";
            l.relativePosition = new Vector3(65.0f, 5.0f);
        }
        public void Close()
        {
            var uiView = UIView.GetAView();

            var trafficManager = uiView.FindUIComponent("UITrafficManager");

            if (trafficManager != null)
            {
                UIView.Destroy(trafficManager);
            }

            UITrafficManager.uistate = UITrafficManager.UIState.None;
            TrafficLightTool.setToolMode(TrafficLightTool.ToolMode.None);
            LoadingExtension.Instance.SetToolMode(TrafficManagerMode.None);

            _uiShown = false;
        }
Exemple #17
0
        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);
            }
        }
Exemple #18
0
        private void clickSwitchTraffic(UIComponent component, UIMouseEventParameter eventParam)
        {
            if (_uistate != UIState.SwitchTrafficLight)
            {
                _uistate = UIState.SwitchTrafficLight;

                buttonSwitchTraffic.focusedBgSprite = "ButtonMenuFocused";
                TrafficLightTool.setToolMode(TrafficLightTool.ToolMode.SwitchTrafficLight);
            }
            else
            {
                _uistate = UIState.None;

                buttonSwitchTraffic.focusedBgSprite = "ButtonMenu";

                TrafficLightTool.setToolMode(TrafficLightTool.ToolMode.None);
            }
        }
Exemple #19
0
        private void clickAddPrioritySigns(UIComponent component, UIMouseEventParameter eventParam)
        {
            if (_uistate != UIState.AddStopSign)
            {
                _uistate = UIState.AddStopSign;

                buttonPrioritySigns.focusedBgSprite = "ButtonMenuFocused";
                TrafficLightTool.setToolMode(TrafficLightTool.ToolMode.AddPrioritySigns);
            }
            else
            {
                _uistate = UIState.None;

                buttonPrioritySigns.focusedBgSprite = "ButtonMenu";

                TrafficLightTool.setToolMode(TrafficLightTool.ToolMode.None);
            }
        }
Exemple #20
0
        private void clickManualControl(UIComponent component, UIMouseEventParameter eventParam)
        {
            if (_uistate != UIState.ManualSwitch)
            {
                _uistate = UIState.ManualSwitch;

                buttonManualControl.focusedBgSprite = "ButtonMenuFocused";
                TrafficLightTool.setToolMode(TrafficLightTool.ToolMode.ManualSwitch);
            }
            else
            {
                _uistate = UIState.None;

                buttonManualControl.focusedBgSprite = "ButtonMenu";

                TrafficLightTool.setToolMode(TrafficLightTool.ToolMode.None);
            }
        }
Exemple #21
0
        private void clickTimedAdd(UIComponent component, UIMouseEventParameter eventParam)
        {
            if (_uistate != UIState.TimedControlNodes)
            {
                _uistate = UIState.TimedControlNodes;

                buttonTimedMain.focusedBgSprite = "ButtonMenuFocused";
                TrafficLightTool.setToolMode(TrafficLightTool.ToolMode.TimedLightsSelectNode);
            }
            else
            {
                _uistate = UIState.None;

                buttonTimedMain.focusedBgSprite = "ButtonMenu";

                TrafficLightTool.setToolMode(TrafficLightTool.ToolMode.None);
            }
        }
Exemple #22
0
        private void clickCrosswalk(UIComponent component, UIMouseEventParameter eventParam)
        {
            if (_uistate != UIState.Crosswalk)
            {
                _uistate = UIState.Crosswalk;

                buttonCrosswalk.focusedBgSprite = "ButtonMenuFocused";
                TrafficLightTool.setToolMode(TrafficLightTool.ToolMode.Crosswalk);
            }
            else
            {
                _uistate = UIState.None;

                buttonCrosswalk.focusedBgSprite = "ButtonMenu";

                TrafficLightTool.setToolMode(TrafficLightTool.ToolMode.None);
            }
        }
        public static bool HasForwardSegment(int segmentID, ushort nodeID, bool debug)
        {
            var node = TrafficLightTool.GetNetNode(nodeID);

            if (node.CountSegments() <= 3)
            {
                var hasLeftSegment  = false;
                var hasRightSegment = false;

                for (int s = 0; s < node.CountSegments(); s++)
                {
                    var segment = node.GetSegment(s);

                    if (segment != 0 && segment != segmentID)
                    {
                        if (isRightSegment(segmentID, segment, nodeID, true) >= 0)
                        {
                            if (debug)
                            {
                                Debug.Log("FORWARD RIGHT: " + segment + " " + GetSegmentDirection(segment, nodeID) + " " + GetSegmentDir(segment, nodeID));
                            }

                            hasRightSegment = true;
                        }

                        if (isLeftSegment(segmentID, segment, nodeID, true) >= 0)
                        {
                            if (debug)
                            {
                                Debug.Log("FORWARDLEFT: " + segment + " " + GetSegmentDirection(segment, nodeID) + " " + GetSegmentDir(segment, nodeID));
                            }
                            hasLeftSegment = true;
                        }
                    }
                }

                if (hasLeftSegment && hasRightSegment)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #24
0
        private void clickLaneRestrictions(UIComponent component, UIMouseEventParameter eventParam)
        {
            if (_uistate != UIState.LaneRestrictions)
            {
                _uistate = UIState.LaneRestrictions;

                buttonLaneRestrictions.focusedBgSprite = "ButtonMenuFocused";

                TrafficLightTool.setToolMode(TrafficLightTool.ToolMode.LaneRestrictions);
            }
            else
            {
                _uistate = UIState.None;

                buttonLaneRestrictions.focusedBgSprite = "ButtonMenu";

                TrafficLightTool.setToolMode(TrafficLightTool.ToolMode.None);
            }
        }
Exemple #25
0
        public void Close()
        {
            if (LoadingExtension.Instance != null)
            {
                var uiView         = UIView.GetAView();
                var trafficManager = uiView.FindUIComponent("UITrafficManager");

                if (trafficManager != null)
                {
                    Destroy(trafficManager);
                }

                UITrafficManager.deactivateButtons();
                TrafficLightTool.SetToolMode(ToolMode.None);
                LoadingExtension.Instance.SetToolMode(TrafficManagerMode.None);

                _uiShown = false;
            }
        }
		public override void Start() {
			if (LoadingExtension.Instance == null) {
				Log.Error("UITrafficManager.Start(): LoadingExtension is null.");
				return;
			}
			TrafficLightTool = LoadingExtension.Instance.TrafficLightTool;

			backgroundSprite = "GenericPanel";
			color = new Color32(75, 75, 135, 255);
			width = 250;
			height = LoadingExtension.IsPathManagerCompatible ? 310 : 230;
			relativePosition = new Vector3(85f, 80f);

			UILabel title = AddUIComponent<UILabel>();
			title.text = "Version 1.4.2";
			title.relativePosition = new Vector3(65.0f, 5.0f);

			int y = 30;
			_buttonSwitchTraffic = _createButton("Switch traffic lights", new Vector3(35f, y), clickSwitchTraffic);
			y += 40;
			_buttonPrioritySigns = _createButton("Add priority signs", new Vector3(35f, y), clickAddPrioritySigns);
			y += 40;
			_buttonManualControl = _createButton("Manual traffic lights", new Vector3(35f, y), clickManualControl);
			y += 40;
			_buttonTimedMain = _createButton("Timed traffic lights", new Vector3(35f, y), clickTimedAdd);
			y += 40;

			if (LoadingExtension.IsPathManagerCompatible) {
				_buttonLaneChange = _createButton("Change lane arrows", new Vector3(35f, y), clickChangeLanes);
				y += 40;
				//buttonLaneRestrictions = _createButton("Road Restrictions", new Vector3(35f, 230f), clickLaneRestrictions);
			}

			_buttonClearTraffic = _createButton("Clear Traffic", new Vector3(35f, y), clickClearTraffic);
			y += 40;

			if (LoadingExtension.IsPathManagerCompatible) {
				_buttonToggleDespawn = _createButton(LoadingExtension.Instance.DespawnEnabled ? "Disable despawning" : "Enable despawning", new Vector3(35f, y), ClickToggleDespawn);
				y += 40;
			}
		}
Exemple #27
0
        public void Update()
        {
            uint currentFrameIndex = Singleton <SimulationManager> .instance.m_currentFrameIndex >> 6;

            if (lastFrame < currentFrameIndex)
            {
                lastFrame = currentFrameIndex;

                foreach (var nodeID in nodeDictionary.Keys)
                {
                    var node = GetNodeSimulation(nodeID);

                    if (node.FlagManualTrafficLights || (node.FlagTimedTrafficLights && node.TimedTrafficLightsActive))
                    {
                        var data = TrafficLightTool.GetNetNode(nodeID);
                        node.SimulationStep(ref data);
                        TrafficLightTool.SetNetNode(nodeID, data);
                    }
                }
            }
        }
        public override void Start()
        {
            _inited = true;

            TrafficLightTool = LoadingExtension.Instance.TrafficLightTool;

            backgroundSprite = "GenericPanel";
            color = new Color32(75, 75, 135, 255);
            width = 250;
            height = !LoadingExtension.PathfinderIncompatibility ? 350 : 270;
            relativePosition = new Vector3(10.48f, 80f);

            UILabel title = AddUIComponent<UILabel>();
            title.text = "Traffic Manager";
            title.relativePosition = new Vector3(65.0f, 5.0f);

            if (!LoadingExtension.PathfinderIncompatibility)
            {
                _buttonSwitchTraffic = _createButton("Switch traffic lights", new Vector3(35f, 30f), clickSwitchTraffic);
                _buttonPrioritySigns = _createButton("Add priority signs", new Vector3(35f, 70f), clickAddPrioritySigns);
                _buttonManualControl = _createButton("Manual traffic lights", new Vector3(35f, 110f), clickManualControl);
                _buttonTimedMain = _createButton("Timed traffic lights", new Vector3(35f, 150f), clickTimedAdd);
                _buttonLaneChange = _createButton("Change lanes", new Vector3(35f, 190f), clickChangeLanes);
                //buttonLaneRestrictions = _createButton("Road Restrictions", new Vector3(35f, 230f), clickLaneRestrictions);
                _buttonCrosswalk = _createButton("Add/Remove Crosswalk", new Vector3(35f, 230f), clickCrosswalk);
                _buttonClearTraffic = _createButton("Clear Traffic", new Vector3(35f, 270f), clickClearTraffic);
                _buttonToggleDespawn = _createButton(LoadingExtension.Instance.DespawnEnabled ? "Disable despawning" : "Enable despawning", new Vector3(35f, 310f), ClickToggleDespawn);

            }
            else
            {
                _buttonSwitchTraffic = _createButton("Switch traffic lights", new Vector3(35f, 30f), clickSwitchTraffic);
                _buttonPrioritySigns = _createButton("Add priority signs", new Vector3(35f, 70f), clickAddPrioritySigns);
                _buttonManualControl = _createButton("Manual traffic lights", new Vector3(35f, 110f), clickManualControl);
                _buttonTimedMain = _createButton("Timed traffic lights", new Vector3(35f, 150f), clickTimedAdd);
                _buttonCrosswalk = _createButton("Add/Remove Crosswalk", new Vector3(35f, 190f), clickCrosswalk);
                _buttonClearTraffic = _createButton("Clear Traffic", new Vector3(35f, 230f), clickClearTraffic);
            }
        }
        public static bool HasRightSegment(int segmentID, ushort nodeID, bool debug)
        {
            var node = TrafficLightTool.GetNetNode(nodeID);

            for (int s = 0; s < node.CountSegments(); s++)
            {
                var segment = node.GetSegment(s);

                if (segment != 0 && segment != segmentID)
                {
                    if (isRightSegment(segmentID, segment, nodeID, true) >= 0)
                    {
                        if (debug)
                        {
                            Debug.Log("RIGHT: " + segment + " " + GetSegmentDirection(segment, nodeID) + " " + GetSegmentDir(segment, nodeID));
                        }
                        return(true);
                    }
                }
            }

            return(false);
        }
        public static bool HasLeftSegment(int segmentId, ushort nodeId, bool debug = false)
        {
            var node = TrafficLightTool.GetNetNode(nodeId);

            for (var s = 0; s < 8; s++)
            {
                var segment = node.GetSegment(s);

                if (segment != 0 && segment != segmentId)
                {
                    if (IsLeftSegment(segmentId, segment, nodeId))
                    {
                        if (debug)
                        {
                            Log.Message("LEFT: " + segment + " " + GetSegmentDir(segment, nodeId));
                        }
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #31
0
        public TimedTrafficSteps(int num, ushort nodeID)
        {
            this.nodeID   = nodeID;
            this.numSteps = num;

            var node = TrafficLightTool.GetNetNode(nodeID);

            for (int s = 0; s < 8; s++)
            {
                var segment = node.GetSegment(s);

                if (segment != 0)
                {
                    var segmentLight = TrafficLightsManual.GetSegmentLight(nodeID, segment);

                    segments.Add(segment);
                    lightMain.Add(segmentLight.GetLightMain());
                    lightLeft.Add(segmentLight.GetLightLeft());
                    lightRight.Add(segmentLight.GetLightRight());
                    lightPedestrian.Add(segmentLight.GetLightPedestrian());
                }
            }
        }
Exemple #32
0
        public static bool HasForwardSegment(int segmentID, ushort nodeID, bool debug = false)
        {
            var node = TrafficLightTool.GetNetNode(nodeID);

            for (int s = 0; s < 8; s++)
            {
                var segment = node.GetSegment(s);

                if (segment != 0 && segment != segmentID)
                {
                    if (!isRightSegment(segmentID, segment, nodeID) && !isLeftSegment(segmentID, segment, nodeID))
                    {
                        if (debug)
                        {
                            Debug.Log("FORWARD: " + segment + " " + GetSegmentDir(segment, nodeID));
                        }
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #33
0
        private bool invalid = false;         // TODO rework

        public TimedTrafficStep(int minTime, int maxTime, ushort nodeId, ushort masterNodeId, List <ushort> groupNodeIds)
        {
            this.nodeId    = nodeId;
            this.minTime   = minTime;
            this.maxTime   = maxTime;
            this.timedNode = TrafficLightsTimed.GetTimedLight(nodeId);

            if (nodeId == masterNodeId)
            {
                this.masterNodeId = null;
            }
            else
            {
                this.masterNodeId = masterNodeId;
            }
            this.groupNodeIds = groupNodeIds;

            var node = TrafficLightTool.GetNetNode(nodeId);

            minFlow = Single.NaN;
            maxWait = Single.NaN;

            endTransitionStart = -1;
            stepDone           = false;

            for (var s = 0; s < 8; s++)
            {
                var segmentId = node.GetSegment(s);
                if (segmentId <= 0)
                {
                    continue;
                }

                addSegment(segmentId);
            }
            rebuildSegmentIds();
        }
Exemple #34
0
 private void clickChangeLanes(UIComponent component, UIMouseEventParameter eventParam)
 {
     if (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt))
     {
         if (_uistate != UIState.LaneChangeAlt)
         {
             _uistate = UIState.LaneChangeAlt;
             buttonLaneChange.focusedBgSprite = "ButtonMenuFocused";
             //LoadingExtension.Instance.SetToolMode(TrafficManagerMode.TrafficLight);
             TrafficLightTool.setToolMode(TrafficLightTool.ToolMode.None);
             ToolsModifierControl.toolController.CurrentTool = LoadingExtension.Instance.RoadCustomizerTool;
             ToolsModifierControl.SetTool <CSL_Traffic.RoadCustomizerTool>();
         }
         else
         {
             _uistate = UIState.None;
             buttonLaneChange.focusedBgSprite = "ButtonMenu";
             TrafficLightTool.setToolMode(TrafficLightTool.ToolMode.None);
         }
     }
     else
     {
         if (_uistate != UIState.LaneChange)
         {
             _uistate = UIState.LaneChange;
             buttonLaneChange.focusedBgSprite = "ButtonMenuFocused";
             TrafficLightTool.setToolMode(TrafficLightTool.ToolMode.LaneChange);
         }
         else
         {
             _uistate = UIState.None;
             buttonLaneChange.focusedBgSprite = "ButtonMenu";
             TrafficLightTool.setToolMode(TrafficLightTool.ToolMode.None);
         }
     }
 }