private void OnPlayerMove(CCC_Player player) { PlayerData p = ConvertPlayerData(player); for (int i = 0; i < Clients.Count; i++) { if (Clients[i].ID == p.ID) { // This code is required because it is not possible to edit // an ObservableCollection outside the UI thread. if (Application.Current != null) { Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, (Action) delegate() { Clients[i] = p; }); } else { Clients[i] = p; } break; } } PlayerMoved(p); }
private void OnClientConnect(CCC_Player player) { PlayerData p = ConvertPlayerData(player); // This code is required because it is not possible to edit // an ObservableCollection outside the UI thread. if (Application.Current != null) { Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, (Action) delegate() { Clients.Add(p); }); } else { Clients.Add(p); } PlayerConnected(p); }
private PlayerData ConvertPlayerData(CCC_Player player) { PlayerData p = new PlayerData(); p.ID = player.ID; p.TeamID = player.TeamID; p.Username = player.Username; p.Health = player.Health; p.Armour = player.Armour; p.Crouching = player.Crouching; PlayerData.Vector3 pos = new PlayerData.Vector3(); pos.X = player.Position.X; pos.Y = player.Position.Y; pos.Z = player.Position.Z; p.Position = pos; PlayerData.Vector3 rot = new PlayerData.Vector3(); rot.X = player.Rotation.X; rot.Y = player.Rotation.Y; rot.Z = player.Rotation.Z; p.Rotation = rot; PlayerData.Vector3 scl = new PlayerData.Vector3(); scl.X = player.Scale.X; scl.Y = player.Scale.Y; scl.Z = player.Scale.Z; p.Scale = scl; PlayerData.Vector3 vel = new PlayerData.Vector3(); vel.X = player.Velocity.X; vel.Y = player.Velocity.Y; vel.Z = player.Velocity.Z; p.Velocity = vel; return(p); }