doghappy / socket.io-client-csharp

socket.io-client implemention for .NET
MIT License
729 stars 125 forks source link

Issue comes when use Socket.On Then Text is not update in canvas but shows right value in textfield in editor #255

Closed SachinTichkule closed 2 years ago

SachinTichkule commented 2 years ago

Example code: void start() { MySocket.socket.On(SocketEvents.usercoins, response => { JSONNode json = JSONNode.Parse(response.GetValue()); Coins = json["coins"]; BetAmount = json["betting"]; SetBetText(json["betting"]); SetCoinText(json["coins"]); }); } I want to update my text. I try force to update canvas.forceUpdate() but didnot update I want to use on functionality. Example:

await MySocket.MyEmitAsync(eventName: SocketEvents.usercoins, data: jsonData, response => { Coins = response["coins"]; BetAmount = response["betting"]; SetBetText(response["betting"]); SetCoinText(response["coins"]); });

doghappy commented 2 years ago

Possible reason: The code that receives the message works in another thread, and the update UI elements needs to be in the UI thread. (This is the experience I got on WinForms or WPF, I don't know Unity)

Perhaps, this library can help you. https://github.com/itisnajim/SocketIOUnity .it is Wrapper for socket.io-client-csharp to work with Unity