Open sticmac opened 2 years ago
Thanks for reporting, @sticmac,
We've added support for multiple callbacks on the other clients for upcoming version 0.15
but it turns out the Unity SDK is still missing this feature (on https://github.com/colyseus/colyseus-unity-sdk/pull/177)
Ideally, the Unity SDK should be able to attach and detach multiple callbacks, for example:
var detachCallback1 = room.OnMessage("xx", () => { /* first */ });
var detachCallback2 = room.OnMessage("xx", () => { /* second */ });
// detaching the "OnMessage" callback:
detachCallback1();
detachCallback2();
I made a pull request (#199) containing a solution like the example you provide :)
When using
ColyseusRoom.OnMessage
twice on the same message ID, I get the following exception:An easy fix would be to modify the
OnMessage
method to take in consideration if a previous message with the given id already exists. However, I wanted to know if this is a bug or a real design choice before submitting a PR.