示例#1
0
        // Update is called once per frame
        void FixedUpdate()
        {
            if (!ticking)
            {
                return;
            }
            Tick += 1;

            netManager.PollEvents();

            if (resimTick < Tick - 1)
            {
                ResetState(resimTick - 1);
                resim(resimTick, Tick);
            }
            else
            {
                resim(Tick, Tick);
            }

            resimTick = Tick;

            if (Tick - maxTicks > earliestTick)
            {
                deleteTicks(earliestTick, Tick - maxTicks);
            }

            earliestTick = Tick - maxTicks;

            SendPacket(HostGameStateOnTickPacket.FromGameState(states[Tick], Tick), DeliveryMethod.Sequenced);
        }
 public static GameState ToGameState(HostGameStateOnTickPacket packet)
 {
     return(new GameState
     {
         ballLocations = packet.ballLocations,
         ballRotations = packet.ballRotations,
         playerLocation = packet.playerLocation,
         playerRotation = packet.playerRotation,
         ballVelocities = packet.ballVelocities,
         ballAngularVelocities = packet.ballAngularVelocities,
         playerVelocity = packet.playerVelocity,
         playerAngularVelocity = packet.playerAngularVelocity
     });
 }
 public static void OnReceive(HostGameStateOnTickPacket packet)
 {
     Client.LoadState(ToGameState(packet), packet.tick);
 }