Character View Sync

Options
Dev
Dev
Im developing a 2d sprite based multiplayer rpg. So after a while of research and little to no help from the community (cough) I have figured out (in my own way) how to sync the view of a character for my system at least. I wanted some insight because I feel the way im doing it isn't as efficient as it could be. If someone could tell me if there's a better way to do this that'd be greatly appreciated.

[PunRPC]
void UpdateInfo(PhotonMessageInfo info)
{
Debug.Log (info.sender.name + " sent this RPC.");

SkinController[] colls = GetComponentsInChildren ();

foreach (SkinController controller in colls)
{
foreach (SpriteCollection spriteColl in controller.skins)
{
object gender;
if (info.sender.customProperties.TryGetValue("Gender", out gender))
{
if ((int)gender == Helper.Constants.Male)
{
spriteColl.sprites = Resources.LoadAll (Helper.Constants.MaleFolder + controller.sprite_type + "/" + spriteColl.sheet.name);
}
else
{
spriteColl.sprites = Resources.LoadAll (Helper.Constants.FemaleFolder + controller.sprite_type + "/" + spriteColl.sheet.name);
}
Debug.Log (info.sender.name + " : " + (int)gender);
}
}
}

// If i sent this RPC, assign the equipment locally
if (info.sender.isLocal)
{
foreach (int equip_id in Session.CharacterData.CharacterEquipment)
{
Debug.Log (equip_id);
if (equip_id != 0)
{
GetComponent ().SetEquipment (EquipmentIndex.GetEquipmentById (equip_id));
}
}
}
else
{
object skin, hair, shirt, pants, shoes;
if (info.sender.customProperties.TryGetValue ("SkinId", out skin)
&& info.sender.customProperties.TryGetValue ("HairId", out hair)
&& info.sender.customProperties.TryGetValue ("ShirtId", out shirt)
&& info.sender.customProperties.TryGetValue ("PantsId", out pants)
&& info.sender.customProperties.TryGetValue ("ShoesId", out shoes))
{
GetComponent ().SetEquipment (EquipmentIndex.GetEquipmentById ((int)skin));
GetComponent ().SetEquipment (EquipmentIndex.GetEquipmentById ((int)hair));
GetComponent ().SetEquipment (EquipmentIndex.GetEquipmentById ((int)shirt));
GetComponent ().SetEquipment (EquipmentIndex.GetEquipmentById ((int)pants));
GetComponent ().SetEquipment (EquipmentIndex.GetEquipmentById ((int)shoes));
}
}
}


So basically what im doing here is first setting the characters gender, then the actual look of the character. The reason why i think this could be better is because i've mixed RPC's with custom properties which could be bad practice? I wasn't able to figure out another way to obtain the other characters equipment id's without trygetvalue'ing them from the custom props. Please any insight is appreciated or any advice.

Thanks,
Dev.

Comments