public void ExecuteUserCmd(IPlayerUserCmdGetter getter, IUserCmd cmd) { if (cmd.PredicatedOnce) { return; } PlayerEntity player = (PlayerEntity)getter.OwnerEntity; //服务器通过tcp指令修改客户端位置 CorrectPositionByServer(cmd, player); CheckPlayerLifeState(player); var updateComponent = player.moveUpdate; updateComponent.LastPosition = player.position.Value.ShiftedToFixedVector3(); updateComponent.Reset(); if (!CanPlayerMove(player)) { return; } player.playerMove.ClearState(); // swimhandler和divehandler未解耦,handler内部函数声明为static,解耦后可以不使用switch MoveType moveType = GetPlayerMoveType(player); switch (moveType) { case MoveType.Land: LandHandler.Move(_contexts, player, cmd.FrameInterval * 0.001f); break; case MoveType.Swim: SwimHandler.Move(_contexts, player, cmd.FrameInterval * 0.001f); break; case MoveType.Dive: DiveHandler.Move(_contexts, player, cmd.FrameInterval * 0.001f); break; case MoveType.Fly: FlyHandler.Move(player, cmd, cmd.FrameInterval * 0.001f); break; default: break; } SyncPlayerMove(player, moveType); }
public void ExecuteUserCmd(IUserCmdOwner owner, IUserCmd cmd) { PlayerEntity player = (PlayerEntity)owner.OwnerEntity; CorrectPositionByServer(cmd, player); CheckPlayerLifeState(player); var updateComponent = player.moveUpdate; updateComponent.LastPosition = player.position.Value; updateComponent.Reset(); if (!CanPlayerMove(player)) { return; } player.playerMove.ClearState(); MoveType moveType = GetPlayerMoveType(player); switch (moveType) { case MoveType.Land: LandHandler.Move(_contexts, player, cmd.FrameInterval * 0.001f); break; case MoveType.Swim: SwimHandler.Move(_contexts, player, cmd.FrameInterval * 0.001f); break; case MoveType.Dive: DiveHandler.Move(_contexts, player, cmd.FrameInterval * 0.001f); break; case MoveType.Fly: FlyHandler.Move(player, cmd, cmd.FrameInterval * 0.001f); break; default: break; } SyncPlayerMove(player, moveType); }