public object GetNodeState(int nodeIndex) { Dictionary <string, object> retObj = new Dictionary <string, object>(); ushort nodeId = SelectNodeId(nodeIndex); for (int i = 0; i < 8; i++) { Dictionary <string, string> segDict = new Dictionary <string, string>(); ushort segId = NetManager.instance.m_nodes.m_buffer[nodeId].GetSegment(i); CustomSegmentLights csls = CustomTrafficLights.GetSegmentLights(nodeId, segId); if (csls != null) { foreach (ExtVehicleType evt in csls.VehicleTypes) { CustomSegmentLight csl = csls.GetCustomLight(evt); if (csl != null) { segDict.Add("vehicle", csl.GetVisualLightState().ToString()); } } retObj.Add("segment" + i, segDict); } } return(retObj); }
public object SetNodeState(int nodeIndex, int segIndex, RoadBaseAI.TrafficLightState vehicleState, RoadBaseAI.TrafficLightState pedestrianState) { ushort nodeId = SelectNodeId(nodeIndex); ushort segId = NetManager.instance.m_nodes.m_buffer[nodeId].GetSegment(segIndex); CustomSegmentLights csls = CustomTrafficLights.GetSegmentLights(nodeId, segId); if (csls != null) { foreach (ExtVehicleType evt in csls.VehicleTypes) { CustomSegmentLight csl = csls.GetCustomLight(evt); if (csl != null) { RoadBaseAI.TrafficLightState currentState = csl.GetVisualLightState(); if (currentState != vehicleState) { if (vehicleState != csl.GetLightMain()) { csl.ChangeLightMain(); } if (vehicleState != csl.GetLightLeft()) { csl.ChangeLightLeft(); } if (vehicleState != csl.GetLightRight()) { csl.ChangeLightRight(); } } } } } else { return(false); } return(true); }