Ejemplo n.º 1
0
 public override void OnConnect(NetDriverConnection connection)
 {
     Assert.IsNull(_serverConnection);
     _serverConnection = new ActorReplicationChannel(new NetConnection(this, connection));
     _serverConnection.ResetTimeoutForTravel();
     connection.outer = _serverConnection;
     Debug.Log("Connected to server (" + connection.address + ")");
 }
Ejemplo n.º 2
0
        public void Tick(float dt, MonoBehaviour loadingContext, ref NetIOMetrics reliableMetrics, ref NetIOMetrics unreliableMetrics)
        {
            if (!isTraveling)
            {
                UpdateTime(Mathf.Min(dt * Time.timeScale, 1 / 3f), dt);
            }

            TickWorldStreaming();

            netDriver.TickClient(Mathf.Min(dt, 1 / 3f), netMessageBytes, ref reliableMetrics, ref unreliableMetrics);

            if (_serverConnection != null)
            {
                if (isTraveling || _wasTraveling)
                {
                    TickTravel(loadingContext);
                    if (!isTraveling)
                    {
                        if (_serverConnection != null)
                        {
                            _serverConnection.ResetTimeout();
                        }
                        FinishTravel();
                        OnLevelStart();
                        GC.Collect();
                    }

                    if (_serverConnection != null)
                    {
                        _serverConnection.ResetTimeoutForTravel();
                    }
                }
                else
                {
                    TickActors(loadingContext);

#if !UNITY_EDITOR
                    if ((_serverConnection != null) && _serverConnection.timedOut)
                    {
                        Debug.LogError("Server connection timed out");
                        _serverConnection.connection.driverConnection.Dispose();
                        _serverConnection = null;
                    }
#endif
                }

                if (_serverConnection != null)
                {
                    _serverConnection.Ping(dt);
                    _serverConnection.connection.driverConnection.GetIOMetrics(ref reliableMetrics, ref unreliableMetrics, true);
                }

                _wasTraveling = isTraveling;
            }
        }
Ejemplo n.º 3
0
        void OnNetMsg(NetMsgs.ClientLevelStarted msg, ActorReplicationChannel channel)
        {
            channel.ResetTimeoutForTravel();

            if (isTraveling)
            {
                if (channel.clientLevel == travelLevel)
                {
                    channel.levelStarted = true;
                }
            }
            else if (channel.clientLevel == currentLevel)
            {
                channel.levelStarted = true;
            }
        }
Ejemplo n.º 4
0
        void OnNetMsg(NetMsgs.ClientFinishedTravel msg, ActorReplicationChannel channel)
        {
            channel.clientLevel = msg.levelName;
            channel.ResetTimeoutForTravel();

            if (isTraveling)
            {
                if (channel.clientLevel != travelLevel)
                {
                    // travel
                    channel.connection.SendReliable(NetMsgs.ClientTravel.New(travelLevel, null));
                }
            }
            else if (channel.clientLevel != currentLevel)
            {
                channel.connection.SendReliable(NetMsgs.ClientTravel.New(currentLevel, null));
            }
        }