public void UpdateClientCarts(NWMCartData cart_data) { cart_tick += 1 * Time.deltaTime; if (cart_tick > tick_rate) { SendAllClientsMessage(host_id, unreliable, cart_data); cart_tick = 0.0f; } }
public void SendCartData(int player_id, Vector3 pos, Vector3 rot) { int id = player_id - 1; NWMCartData cart_data = new NWMCartData(); cart_data.SetArrays(); cart_data.player_ID = player_id; cart_data.POSX[id] = pos.x; cart_data.POSY[id] = pos.y; cart_data.POSZ[id] = pos.z; cart_data.ROTX[id] = rot.x; cart_data.ROTY[id] = rot.y; cart_data.ROTZ[id] = rot.z; SendServerMessage(cart_data, unreliable); }
private void SendUpdatedCartData() { NWMCartData cart_data = new NWMCartData(); cart_data.SetArrays(); for (int i = 0; i < player_carts.Count; i++) { cart_data.POSX[i] = player_carts[i].transform.position.x; cart_data.POSY[i] = player_carts[i].transform.position.y; cart_data.POSZ[i] = player_carts[i].transform.position.z; cart_data.ROTX[i] = player_carts[i].transform.rotation.x; cart_data.ROTY[i] = player_carts[i].transform.rotation.y; cart_data.ROTZ[i] = player_carts[i].transform.rotation.z; } server.UpdateClientCarts(cart_data); }
public void SetPlayerCartData(NWMCartData cart_data) { int id = cart_data.player_ID - 1; for (int i = 0; i < player_carts.Count; i++) { //only want to get updates from cart_data of the player who sent it if (i != id) { continue; } Vector3 new_position = new Vector3(cart_data.POSX[i], cart_data.POSY[i], cart_data.POSZ[i]); Vector3 new_rotation = new Vector3(cart_data.ROTX[i], cart_data.ROTY[i], cart_data.ROTZ[i]); Vector3 current_position = player_carts[i].transform.position; Vector3 current_rotation = player_carts[i].transform.rotation.eulerAngles; player_carts[i].transform.position = new_position; player_carts[i].transform.rotation = Quaternion.Euler(new_rotation); } }
public void ReceiveCartData(NWMCartData cart_data) { //go through cart data for each user for (int i = 0; i < MAX_USER; i++) { if ((i + 1) == player_id) // dont want to receive our own data { continue; } Vector3 cart_position = new Vector3(cart_data.POSX[i], cart_data.POSY[i], cart_data.POSZ[i]); Vector3 cart_rotation = new Vector3(cart_data.ROTX[i], cart_data.ROTY[i], cart_data.ROTZ[i]); //check the networked players ids with data data indexes for (int j = 0; j < network_GM.networked_players.Count; j++) { if ((i + 1) == network_GM.networked_players[j].player_id) { network_GM.networked_players[j].SetCartValues(cart_position, cart_rotation); } } } }
private void OnDataRecieved(int client_id, int channel_id, int host_id, NetworkMessage message) { switch (message.operation) { case NetworkOperation.none: break; case NetworkOperation.set_ready: NWMPlayerReady ready_message = (NWMPlayerReady)message; if (lobby) { lobby.SetPlayerReadyState(client_id, ready_message.ready_state); lobby.SetPlayerName(client_id, ready_message.player_name); } else if (game) { game.ClientReady(client_id, ready_message.ready_state); } break; case NetworkOperation.cart_data: NWMCartData cart_message = (NWMCartData)message; game.SetPlayerCartData(cart_message); break; case NetworkOperation.grid_single: NWMGridData grid_message = (NWMGridData)message; game.SetGridTile(grid_message); break; case NetworkOperation.cart_off_tracks: ReceiveOffTrackInfo(client_id); break; } }
private void OnDataReceived(int channel_id, int host_id, NetworkMessage message) { switch (message.operation) { case NetworkOperation.none: break; case NetworkOperation.set_ready: break; case NetworkOperation.cart_data: NWMCartData cart_data = (NWMCartData)message; ReceiveCartData(cart_data); break; case NetworkOperation.grid_single: NWMGridData grid_data = (NWMGridData)message; ReceiveSingleGridData(grid_data); break; case NetworkOperation.user_counter: NWMUserCount user_counter = (NWMUserCount)message; ReceiveUserCount(user_counter); break; case NetworkOperation.scene_load: NWMSceneLoad scene_load = (NWMSceneLoad)message; ReceiveSceneToLoad(scene_load); break; case NetworkOperation.assign_num: NWMAssignPlayerNum assigner = (NWMAssignPlayerNum)message; player_id = assigner.num; Debug.Log(client_id); break; case NetworkOperation.gold_pos: NWMGoldUpdate goldUpdate = (NWMGoldUpdate)message; ReceiveGoldPositionUpdate(goldUpdate); break; case NetworkOperation.player_score: NWMScoreUpdate scoreUpdate = (NWMScoreUpdate)message; ReceiveScoreUpdate(scoreUpdate); break; case NetworkOperation.player_info: NWMPlayerIDUpdate idUpdate = (NWMPlayerIDUpdate)message; ReceivePlayerDataUpdate(idUpdate); break; case NetworkOperation.game_start: NWMGameStart start_msg = (NWMGameStart)message; SetClientGameStarted(start_msg); break; case NetworkOperation.player_respawn: NWMPlayerRespawn respawn_data = (NWMPlayerRespawn)message; ReceivePlayerRepsawnData(respawn_data); break; case NetworkOperation.timer_seconds: NWMTimerUpdate timer_data = (NWMTimerUpdate)message; ReceiveUpdateTimer(timer_data); break; case NetworkOperation.game_finished: NWMGameFinishedSendInfo game_finished_info = (NWMGameFinishedSendInfo)message; ReceiveGameFinishedInfo(game_finished_info); break; } }