- Home /
Photon Custom Serializer Help
Hello,
I am trying to create a custom serializer for my Photon project. Below is the class I am trying to create a serializer for.
public class PlayerProperties {
public string name;
public int id;
public PhotonView playerView;
public Team team;
public bool isLocal;
}
The "Team" enum is below.
public enum Team : byte {
Blue,
Yellow,
Red,
Green,
NullTeam
}
And below is what I have created so far. This serializer is not working, however.
public static byte[] SerializePlayerProperties(object o) {
PlayerProperties player = (PlayerProperties)o;
MemoryStream ms = new MemoryStream(4 * 4);
ms.Write(System.Text.Encoding.UTF8.GetBytes(player.name), 0, 4);
ms.Write(BitConverter.GetBytes(player.id), 0, 4);
ms.Write(BitConverter.GetBytes(player.playerView.viewID), 0, 4);
ms.Write(BitConverter.GetBytes((byte)player.team), 0, 4);
ms.Write(BitConverter.GetBytes(player.isLocal), 0, 4);
return ms.ToArray();
}
It says it was unable to serialize. Any help/guidance is greatly appreciated. Thank you.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613185529im_/https://answers.unity.com/themes/thub/images/avi.jpg)