Ejemplo n.º 1
0
        public void Start()
        {
            SyncNetworkManager.singleton._OnStartServer += () =>
            {
                NetworkServer.RegisterHandler(CustomMsgType.Latency, (nmsg) =>
                {
#if INCLUDE_UPDATE
                    _conectionLatencyPool[nmsg.conn.connectionId] = nmsg.ReadMessage <LatencyMessage>();
#else
                    UpdateTable(nmsg.conn.connectionId, nmsg.ReadMessage <LatencyMessage>());
#endif
                });
            };

            SyncNetworkManager.singleton._OnServerDisconnect += (conn) =>
            {
                _conectionLatencyTable.Remove(conn.connectionId);
            };

            SyncNetworkManager.singleton._OnStartClient += () =>
            {
                if (SyncNet.isSlaver)
                {
                    SyncNet.client.RegisterHandler(CustomMsgType.Latency, (msg) =>
                    {
#if INCLUDE_UPDATE
                        _lastMsg = msg.ReadMessage <LatencyMessage>();
#else
                        SyncNet.client.Send(CustomMsgType.Latency, msg.ReadMessage <LatencyMessage>());
#endif
                    });
                }
            };
        }
Ejemplo n.º 2
0
        public void Update()
        {
            if (SyncNet.isServer)
            {
                _conectionLatencyTable.Values.ToList().ForEach(d => d._recieved = false);
                NetworkServer.SendToAll(CustomMsgType.Latency, new LatencyMessage()
                {
                    serverTime = Network.time
                });


#if INCLUDE_UPDATE
                if (_conectionLatencyPool.Any())
                {
                    _conectionLatencyPool.ToList().ForEach(pair =>
                    {
                        UpdateTable(pair.Key, pair.Value);
                    });
                    _conectionLatencyPool.Clear();
                }
#endif
            }

#if INCLUDE_UPDATE
            if (SyncNet.isSlaver)
            {
                if (_lastMsg != null)
                {
                    SyncNet.client.Send(CustomMsgType.Latency, _lastMsg);
                    _lastMsg = null;
                }
            }
#endif
        }
Ejemplo n.º 3
0
        void UpdateTable(int connectionId, LatencyMessage lmsg)
        {
            Data data;

            if (!_conectionLatencyTable.TryGetValue(connectionId, out data))
            {
                _conectionLatencyTable[connectionId] = data = new Data();
            }

            var latency = (float)(Network.time - lmsg.serverTime) * 0.5f;

            data.Add(latency);
            data._recieved = true;
        }