Пример #1
0
        public override void OnAttachedToClient(Client client)
        {
            base.OnAttachedToClient(client);

            vehicles.SetupVehicleSlots(client.Players.SlotsCount);

            for(int i = 0; i < client.Players.SlotsCount; ++i)
            {
                RemotePlayer player = client.Players.GetPlayerInSlot(i);

                VehicleNetworkState state = new VehicleNetworkState();
                vehcileNetworkStates.Add(state);

                if (player == null)
                    continue;

                if (player == client.LocalPlayer)
                {
                    vehicles.SpawnLocalVehicle(i);

                    localPlayerState = state;
                }
                else
                {
                    vehicles.SpawnRemotevehicle(i);
                }
            }
        }
Пример #2
0
    public void ToNetworkState(VehicleNetworkState state)
    {
        state.InputForward = Input.Forward;
        state.InputBackward = Input.Back;
        state.InputTurn = Input.Turn;

        state.PositionX = Position.x;
        state.PositionY = Position.z;

        state.Rotation = Rotation.eulerAngles.y;

        state.LocalVelocityX = LocalVelocity.x;
        state.LocalVelocityY = LocalVelocity.y;
    }
Пример #3
0
    // Convert to and from network state class as server should not reference unity classes
    public void FromNetworkState(VehicleNetworkState state)
    {
        Input.Forward = state.InputForward;
        Input.Back = state.InputBackward;
        Input.Turn = state.InputTurn;

        Position.x = state.PositionX;
        Position.y = 0.0f;
        Position.z = state.PositionY;

        Rotation = Quaternion.Euler(0.0f, state.Rotation, 0.0f);

        LocalVelocity.x = state.LocalVelocityX;
        LocalVelocity.y = 0.0f;
        LocalVelocity.z = state.LocalVelocityY;
    }
Пример #4
0
        public CarsServerGameMode(Server server)
            : base(server)
        {
            for (int i = 0; i < Server.Players.SlotsCount; ++i)
            {
                RemotePlayer player = server.Players.GetPlayerInSlot(i);

                VehicleNetworkState state = new VehicleNetworkState();

                carSlots.Add(state);

                if (player != null)
                {
                    SpawnPlayer(i, 0.0f, 0.0f, 0.0f);
                }
            }
        }