void Update()
    {
        if (!_isClientConnected)
        {
            return;
        }

        if (!NetworkManagerInstance.client.handlers.ContainsKey(SERVER_MESSAGE_TYPE_ID))
        {
            NetworkManagerInstance.client.RegisterHandler(SERVER_MESSAGE_TYPE_ID, networkMessage =>
            {
                var message = networkMessage.ReadMessage <PacketFlowMessage>();
                _messageQueue.Enqueue(message);
            });
        }

        while (!_messageQueue.IsEmpty)
        {
            PacketFlowMessage message;
            if (_messageQueue.TryDequeue(out message))
            {
                var @event = NetworkEventAndPacketFlowMessageBidirectionalMapper.Map(message);
                _eventSubject.OnNext(@event);
                Debug.Log("Message received: " + message.payload);
            }
        }
    }
Example #2
0
    public void SendEvent(NetworkEvent @event)
    {
        var eventToSendAcrossWire = NetworkEventAndPacketFlowMessageBidirectionalMapper.Map(@event);

        NetworkServer.SendToAll(SERVER_MESSAGE_TYPE_ID, eventToSendAcrossWire);
    }