public void UpdateVisuals()
        {
#if TRACE
            Singleton <CodeProfiler> .instance.Start("CustomSegmentLight.UpdateVisuals");
#endif
            var instance = Singleton <NetManager> .instance;

            uint currentFrameIndex = Singleton <SimulationManager> .instance.m_currentFrameIndex;
            uint num = (uint)(((int)NodeId << 8) / 32768);

            RoadBaseAI.TrafficLightState vehicleLightState;
            RoadBaseAI.TrafficLightState pedestrianLightState;

            RoadBaseAI.TrafficLightState mainLight  = LightMain;
            RoadBaseAI.TrafficLightState leftLight  = LightLeft;
            RoadBaseAI.TrafficLightState rightLight = LightRight;

            switch (CurrentMode)
            {
            case Mode.Simple:
                leftLight  = mainLight;
                rightLight = mainLight;
                break;

            case Mode.SingleLeft:
                rightLight = mainLight;
                break;

            case Mode.SingleRight:
                leftLight = mainLight;
                break;

            case Mode.All:
            default:
                break;
            }

            vehicleLightState = GetVisualLightState();

            pedestrianLightState = lights.PedestrianLightState == null ? RoadBaseAI.TrafficLightState.Red : (RoadBaseAI.TrafficLightState)lights.PedestrianLightState;

            uint now = ((currentFrameIndex - num) >> 8) & 1;
            CustomRoadAI.OriginalSetTrafficLightState(true, NodeId, ref instance.m_segments.m_buffer[SegmentId], now << 8, vehicleLightState, pedestrianLightState, false, false);
            CustomRoadAI.OriginalSetTrafficLightState(true, NodeId, ref instance.m_segments.m_buffer[SegmentId], (1u - now) << 8, vehicleLightState, pedestrianLightState, false, false);
#if TRACE
            Singleton <CodeProfiler> .instance.Stop("CustomSegmentLight.UpdateVisuals");
#endif
        }
        public void UpdateVisuals()
        {
            var instance = Singleton <NetManager> .instance;

            ushort nodeId            = lights.NodeId;
            uint   currentFrameIndex = Singleton <SimulationManager> .instance.m_currentFrameIndex;
            uint   num = (uint)(((int)nodeId << 8) / 32768);

            RoadBaseAI.TrafficLightState vehicleLightState;
            RoadBaseAI.TrafficLightState pedestrianLightState;

            RoadBaseAI.TrafficLightState mainLight  = LightMain;
            RoadBaseAI.TrafficLightState leftLight  = LightLeft;
            RoadBaseAI.TrafficLightState rightLight = LightRight;

            switch (CurrentMode)
            {
            case LightMode.Simple:
                leftLight  = mainLight;
                rightLight = mainLight;
                break;

            case LightMode.SingleLeft:
                rightLight = mainLight;
                break;

            case LightMode.SingleRight:
                leftLight = mainLight;
                break;

            case LightMode.All:
            default:
                break;
            }

            vehicleLightState    = GetVisualLightState();
            pedestrianLightState = lights.PedestrianLightState == null ? RoadBaseAI.TrafficLightState.Red : (RoadBaseAI.TrafficLightState)lights.PedestrianLightState;

#if DEBUGVISUALS
            Log._Debug($"Setting visual traffic light state of node {NodeId}, seg. {SegmentId} to vehicleState={vehicleLightState} pedState={pedestrianLightState}");
#endif

            uint now = ((currentFrameIndex - num) >> 8) & 1;
            CustomRoadAI.OriginalSetTrafficLightState(true, nodeId, ref instance.m_segments.m_buffer[SegmentId], now << 8, vehicleLightState, pedestrianLightState, false, false);
            CustomRoadAI.OriginalSetTrafficLightState(true, nodeId, ref instance.m_segments.m_buffer[SegmentId], (1u - now) << 8, vehicleLightState, pedestrianLightState, false, false);
        }
        /*public void ChangeLightPedestrian() {
         *      if (PedestrianEnabled) {
         *              var invertedLight = LightPedestrian == RoadBaseAI.TrafficLightState.Green
         *                      ? RoadBaseAI.TrafficLightState.Red
         *                      : RoadBaseAI.TrafficLightState.Green;
         *
         *              LightPedestrian = invertedLight;
         *              UpdateVisuals();
         *      }
         * }*/

        /*RoadBaseAI.TrafficLightState lastVehicleLightState = RoadBaseAI.TrafficLightState.Red;
         * RoadBaseAI.TrafficLightState lastPedestrianLightState = RoadBaseAI.TrafficLightState.Red;*/

        public void UpdateVisuals()
        {
            var instance = Singleton <NetManager> .instance;

            uint currentFrameIndex = Singleton <SimulationManager> .instance.m_currentFrameIndex;
            uint num = (uint)(((int)NodeId << 8) / 32768);

            RoadBaseAI.TrafficLightState vehicleLightState;
            RoadBaseAI.TrafficLightState pedestrianLightState;

            RoadBaseAI.TrafficLightState mainLight  = LightMain;
            RoadBaseAI.TrafficLightState leftLight  = LightLeft;
            RoadBaseAI.TrafficLightState rightLight = LightRight;

            switch (CurrentMode)
            {
            case Mode.Simple:
                leftLight  = mainLight;
                rightLight = mainLight;
                break;

            case Mode.SingleLeft:
                rightLight = mainLight;
                break;

            case Mode.SingleRight:
                leftLight = mainLight;
                break;

            case Mode.All:
            default:
                break;
            }

            // any green?
            if (mainLight == RoadBaseAI.TrafficLightState.Green ||
                leftLight == RoadBaseAI.TrafficLightState.Green ||
                rightLight == RoadBaseAI.TrafficLightState.Green)
            {
                vehicleLightState = RoadBaseAI.TrafficLightState.Green;
            }
            else               // all red?
            if (mainLight == RoadBaseAI.TrafficLightState.Red &&
                leftLight == RoadBaseAI.TrafficLightState.Red &&
                rightLight == RoadBaseAI.TrafficLightState.Red)
            {
                vehicleLightState = RoadBaseAI.TrafficLightState.Red;
            }
            else               // any red+yellow?
            if (mainLight == RoadBaseAI.TrafficLightState.RedToGreen ||
                leftLight == RoadBaseAI.TrafficLightState.RedToGreen ||
                rightLight == RoadBaseAI.TrafficLightState.RedToGreen)
            {
                vehicleLightState = RoadBaseAI.TrafficLightState.RedToGreen;
            }
            else
            {
                vehicleLightState = RoadBaseAI.TrafficLightState.GreenToRed;
            }

            //pedestrianLightState = LightPedestrian;
            pedestrianLightState = lights.PedestrianLightState == null ? RoadBaseAI.TrafficLightState.Red : (RoadBaseAI.TrafficLightState)lights.PedestrianLightState;

            uint now = ((currentFrameIndex - num) >> 8) & 1;

            CustomRoadAI.OriginalSetTrafficLightState(true, NodeId, ref instance.m_segments.m_buffer[SegmentId], now << 8, vehicleLightState, pedestrianLightState, false, false);
            CustomRoadAI.OriginalSetTrafficLightState(true, NodeId, ref instance.m_segments.m_buffer[SegmentId], (1u - now) << 8, vehicleLightState, pedestrianLightState, false, false);

            /*if (vehicleLightState != lastVehicleLightState || pedestrianLightState != lastPedestrianLightState) {
             *      // force rendering
             *      Singleton<NetManager>.instance.UpdateSegmentRenderer(segmentId, true);
             * }
             *
             * lastVehicleLightState = vehicleLightState;
             * lastPedestrianLightState = pedestrianLightState;*/
        }