colyseus / colyseus-unity-sdk

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

about 0.15 state.player.listen("field", (value)) #219

Closed yty closed 8 months ago

yty commented 8 months ago

Schema's onChange behaviour change](https://docs.colyseus.io/migrating/0.15/?h=onadd#schema-callbacks-api-slightly-changed)

// 0.15 (new)
state.player.onChange(() =>{
    console.log("player changed!");
});
state.player.listen("field", (value) => {
    console.log(value);
})

I can't find the listen method in c#. How can I use it?

image

yty commented 8 months ago

https://docs.colyseus.io/state/schema.zh_cn/?h=listen#listenprop-callback

I found OnCurrentTurnChange here, how to implement it?

state.OnCurrentTurnChange((currentValue, previousValue) => {
    Debug.Log(currentValue);
    Debug.Log(previousValue);
})
using Colyseus.Schema;

public partial class Player : Schema
{
    [Type(0, "number")]
    public float x = default(float);

    [Type(1, "number")]
    public float y = default(float);
}
endel commented 8 months ago

Hi @yty, the schema-codegen tool is responsible for generating the listeners per property on C#

yty commented 8 months ago

@endel

thank you, I understand. Suggest adding it to Example by default.

0.15.5 \ Example \ Scripts \ Scheme \ MyRoomState.cs 0.15.5 \ Example \ Scripts \ Scheme \ Player.cs