colyseus / colyseus-unity-sdk

⚔ Colyseus Multiplayer SDK for Unity
https://docs.colyseus.io/getting-started/unity-sdk/
MIT License
378 stars 104 forks source link

[WIP] Allow custom types #90

Closed ADustyOldMuffin closed 4 years ago

ADustyOldMuffin commented 5 years ago

Closes #89

This will allow users to declare custom objects to send via the room.Send(SerializableObject)

ADustyOldMuffin commented 5 years ago

Hey @endel I just wanted to check and make sure I was headed in the right direction.

My idea was to make the room.Send() method generic since it is more efficient for high volume calls, but to change connection.Send() to possibly be generic or an object that requires a serializable object for data to send, and a protocol.

On a side note I think protocol should be an enum instead of static int (unless there is a specific reason to not have them like that).

Wenish commented 5 years ago

@ADustyOldMuffin if im correct await room.Send(new { move = "left" }); still works right? or is it a breaking change?

ADustyOldMuffin commented 5 years ago

I believe it should work as requiring a generic should be the same, but I can test when I have the chance. I was just checking to see that I was on the right path or if someone had another idea.

endel commented 4 years ago

Thanks for your PR @ADustyOldMuffin, I've had a strange issue using for the Send method, so ended up using a simpler approach here - just suppressing the type information, which allows to encode and send custom data types: https://github.com/colyseus/colyseus-unity3d/commit/1954d98aa47caaec2b17d40e6fed2408a189ebb4#diff-71c9fc0505f323e7aa448bcafd028c94R31