// you can send the message here if you already know // everything about the character at the time of player // or at a later time when the user submits his preferences private void OnClientAuthenticated(INetworkPlayer player) { var mmoCharacter = new CreateMMOCharacterMessage { // populate the message with your data name = "player name", race = Race.Human, eyeColor = Color.red, hairColor = Color.black, }; player.Send(mmoCharacter); }
private void OnCreateCharacter(INetworkPlayer player, CreateMMOCharacterMessage msg) { var prefab = GetPrefab(msg); // create your character object // use the data in msg to configure it var character = Instantiate(prefab); // set syncVars before telling mirage to spawn character // this will cause them to be sent to client in the spawn message character.PlayerName = msg.name; character.hairColor = msg.hairColor; character.eyeColor = msg.eyeColor; // spawn it as the character object ServerObjectManager.AddCharacter(player, character.Identity); }
private CustomCharacter GetPrefab(CreateMMOCharacterMessage msg) { // get prefab based on race CustomCharacter prefab; switch (msg.race) { case Race.Human: prefab = HumanPrefab; break; case Race.Elvish: prefab = ElvishPrefab; break; case Race.Dwarvish: prefab = DwarvishPrefab; break; // default case to check that client sent valid race. // the only reason it should be invalid is if the client's code was modified by an attacker // throw will cause the client to be kicked default: throw new InvalidEnumArgumentException("Invalid race given"); } return(prefab); }