public void OnUdpReceived(BitBuffer buffer, ushort packetTimestamp) { bool resetPacketTimestamp; lock (SmallLock) { resetPacketTimestamp = _resetPacketTimestamp; _resetPacketTimestamp = false; } if (resetPacketTimestamp) { _lastPacketTimestamp = packetTimestamp; } else if (!DoubleProtocol.IsPacketNewest(ref _lastPacketTimestamp, packetTimestamp)) { return; } byte[] bytes = buffer.ReadBytes(); // ReSharper disable once ConvertToLocalFunction Action handler = () => { if (_client != null) { _handlerBuffer.SetContents(bytes); UdpHandler(_handlerBuffer); } }; // ReSharper disable once PossibleNullReferenceException int netDelayIncrease = DoubleProtocol.TripTime(_client.ConnectionStartTimestamp, packetTimestamp); if (!NetworkUtils.SimulateNetworkConditions || NetworkUtils.IsServer) { UnityFixedDispatcher.InvokeNoDelay(handler); } else if (!NetworkUtils.SimulateLosingPacket) { int delay = NetworkUtils.SimulatedNetDelay; netDelayIncrease += delay; UnityFixedDispatcher.InvokeDelayed(delay, handler); } else { return; } UdpNetDelay += (netDelayIncrease - UdpNetDelay) * 0.1f; }