CharactersAvailableMsg MakeCharactersAvailableMessage(string account) { List <string> names = Database.singleton.CharactersForAccount(account); List <Player> characters = new List <Player>(); foreach (string character in names) { GameObject player = Database.singleton.CharacterLoad(character, playerClasses, true); characters.Add(player.GetComponent <Player>()); } CharactersAvailableMsg message = new CharactersAvailableMsg(); message.Load(characters); characters.ForEach(player => Destroy(player.gameObject)); return(message); }
// helper function to make a CharactersAvailableMsg from all characters in // an account CharactersAvailableMsg MakeCharactersAvailableMessage(string account) { // load from database List<Player> characters = Database.CharactersForAccount(account) .Select(character => Database.CharacterLoad(character, GetPlayerClasses())) .Select(go => go.GetComponent<Player>()) .ToList(); // construct the message CharactersAvailableMsg message = new CharactersAvailableMsg(); message.Load(characters); // destroy the temporary players again and return the result characters.ForEach(player => Destroy(player.gameObject)); return message; }
// helper function to make a CharactersAvailableMsg from all characters in // an account CharactersAvailableMsg MakeCharactersAvailableMessage(string account) { // load from database // (avoid Linq for performance/gc. characters are loaded frequently!) List <Player> characters = new List <Player>(); foreach (string characterName in Database.singleton.CharactersForAccount(account)) { GameObject player = Database.singleton.CharacterLoad(characterName, playerClasses, true); characters.Add(player.GetComponent <Player>()); } // construct the message CharactersAvailableMsg message = new CharactersAvailableMsg(); message.Load(characters); // destroy the temporary players again and return the result characters.ForEach(player => Destroy(player.gameObject)); return(message); }