コード例 #1
0
    void FixedUpdate()
    {
        if (networkObject == null)
        {
            return;
        }

        // Everyone that is not the server or the controlling player will just set the position.
        if (!networkObject.IsServer && !_isOwner)
        {
            transform.position = networkObject.position;
            return;
        }

        // We advance one frame in the simulation
        _listener.AdvanceFrame();

        // The controlling player saves this Frame with his last input and action recorded.
        if (_isOwner)
        {
            _listener.SaveFrame();
        }

        // The server and the controlling player play the frames they saved.
        _listener.PlayFrame(transform);

        // We allow the server to catch up if he is too far behind because of prolonged latency
        if (networkObject.IsServer && _listener.FramesToPlay.Count > _listener.FrameSyncRate)
        {
            _listener.PlayFrame(transform);
        }

        // Reconcile frames when the client is too far away from the server-position.
        if (_isOwner)
        {
            _listener.ReconcileFrames();
        }

        // The server updates the position on the network for everyone else.
        if (networkObject.IsServer)
        {
            networkObject.position = transform.position;
        }
    }