Send class into Photon [No serialization]

Options
RandomMan
RandomMan
edited July 2017 in Photon Server
I have a class with about 10 variables. I want to send List of this class Server>Clients .(this class in common) I was tried it using List of object[] but it's very weird way. Are there other ways? But I don't want to serialize because it's very hard, serializing of Vector2 was about 100 lines of code.

I saw in One Project [DataMember], I think it's what I need but I don't know how to use it.

Comments

  • chvetsov
    chvetsov mod
    edited August 2017
    Options
  • RandomMan
    Options
    I read this tutorial many times but still didn't understand how it. Can you give me an example, how to send into Photon array of class where Vector2 and int? (So I need serialize Vector2 and class)
  • chvetsov
    chvetsov mod
    edited August 2017
    Options
    @RandomMan

    lets assume Serialize is a method of your type. you registered this method using PhotonPeer.RegisterType on client and you also should create similar method on server
    public static readonly byte[] memVector2 = new byte[3 * 4];//allocate memory for vector2 and int
    private static short Serialize(StreamBuffer outStream, object customobject)
    {
         YourType yourTypeInstance = (YourType)customObject
        Vector2 vo = yourTypeInstance.Vector2;
        lock (memVector2)
        {
            byte[] bytes = memVector2;
            int index = 0;
            Protocol.Serialize(vo.x, bytes, ref index);
            Protocol.Serialize(vo.y, bytes, ref index);
            Protocol.Serialize(yourTypeInstance.Int, bytes, ref index);
            outStream.Write(bytes, 0, 3 * 4);
        }
        return 2 * 4;
    }