Serialization in PhotonServer

How to make serialization class in PhotonServer? Wanna make something like Vector2 in Unity for not send x and y always.

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @RandomMan,

    You can find an example here.
  • RandomMan
    RandomMan
    edited July 2017
    I don't understand what is it "typeCode" there and what should I write there.

    here is my code on Common
    https://pastebin.com/tLpGu4xD (use pastebin because there many code and it's looks bad on this site)
    and on Server
    Protocol.TryRegisterCustomType(typeof(Vector2Net), idkwhatthere, Vector2Net.Serialize, Vector2Net.Deserialize);

    As you see, I just need Vector2 on Server.
  • And I'm a bit don't understand. Shall I deserialize/serialize it on server or on client on or both of them??
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited July 2017
    I don't understand what is it "typeCode" there and what should I write there.
    It's just a byte to identify the custom type.
    Shall I deserialize/serialize it on server or on client on or both of them??

    Yes you should implement custom type registration on both ends, if you use C# client then the code should be exactly the same.
    Here is PUN's version of the Serilization in Photon doc you can find:

    - the custom types included in PUN by default.
    - the code used for Unity's Vector2.
  • Thanks. I did "Byte" to identify custom type but still have one problem
    public static object Deserialize(byte[] data) { Vector2Net result = new Vector2Net(); result.x = data[0]; result.y = data[1]; return result; } public static byte[] Serialize(object customType) { Vector2Net newVector = (Vector2Net)customType; return new byte[] { newVector }; }
    How to I should serialize? what return?
  • FOUND SOLUTION! I used an example from Photon.MMO Project!

  • Can I ask you something , Serialize data in sever and send event, but raiseEvent in client i have problem, Deserialize data from raiseEvent
    pressed type object but
    can't get value
  • hi, @tuanvu
    are you sure that data were send? please check logs first in your solution 'log' folder, in deploy/log and bin_Win64/log folders

    could you provide an example of what you sending?

    best,
    ilya

  • thank,@chvetsov mod

    I fixed my error, after reading the doc, I understood some problems, the code had to manually assign values ​​to each damn class value ,
    I'm really stupid
  • you managed to fix it - that is very good news

    best,
    ilya