示例#1
0
    private void Update()
    {
        switch (Mode)
        {
        case Mode.Server:
            TargetTickPerSecond = _server.TickRate;
            break;

        case Mode.Client:
            TargetTickPerSecond = _client.TickRate;
            break;
        }

        while (_lastUpdate < Time.realtimeSinceStartup)
        {
            _lastUpdate += 1f / TargetTickPerSecond;
            _tickCount++;
            switch (Mode)
            {
            case Mode.Server:
                _server.Execute();
                _serverFeature.Execute();
                _serverFeature.Cleanup();
                break;

            case Mode.Client:
                _client.UpdateNetwork();
                _client.Execute();
                _clientFeature.Execute();
                _clientFeature.Cleanup();
                break;
            }
        }

        _timer -= Time.deltaTime;
        if (_timer < 0f)
        {
            _totalTicksThisSecond = _tickCount;
            _tickCount            = 0;
            _timer += 1;
        }
    }
    private void Update()
    {
        switch (Mode)
        {
        case Mode.Server:
            TargetTickPerSecond = _server.TickRate;
            break;

        case Mode.Client:
            TargetTickPerSecond = _client.TickRate;
            break;
        }

        while (_lastUpdate < Time.realtimeSinceStartup)
        {
            _lastUpdate += 1f / TargetTickPerSecond;
            _tickCount++;
            switch (Mode)
            {
            case Mode.Server:
                if (!_isInit)
                {
//                        _server.Initialize();
                    _serverFeature.Initialize();
                    _isInit = true;
                }
                else
                {
                    _server.Execute();
                    _serverFeature.Execute();
                    _serverFeature.Cleanup();
                }

                break;

            case Mode.Client:
                if (!_isInit)
                {
                    _clientFeature.Initialize();
                    _isInit = true;
                }
                else
                {
                    _client.UpdateNetwork();
                    _client.Execute();
                    _clientFeature.Execute();
                    _clientFeature.Cleanup();
                }

                break;
            }
        }

        if (Mode == Mode.Client)
        {
            if (!_isClientInit)
            {
                _clientViewFeature.Initialize();
                _isClientInit = true;
            }
            else
            {
                _clientViewFeature.Execute();
            }
        }


        _timer -= Time.deltaTime;
        if (_timer < 0f)
        {
            _totalTicksThisSecond = _tickCount;
            _tickCount            = 0;
            _timer += 1;
        }
    }