Send class into Photon [No serialization]
Options
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.
I saw in One Project [DataMember], I think it's what I need but I don't know how to use it.
0
Comments
-
hi, @RandomMan
you may/should use custom types here is the docs. https://doc.photonengine.com/en-us/realtime/current/reference/serialization-in-photon#custom_types_in_c_
best,
ilya0 -
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)0
-
@RandomMan
lets assume Serialize is a method of your type. you registered this method usingPhotonPeer.RegisterType
on client and you also should create similar method on serverpublic 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; }
0