Colyseus Unity3d

by gamestdio

Multiplayer Game Client for Unity

( Crawled 32 minutes ago )

Multiplayer Game Client for Unity / C#


Copy Assets/Plugins into your Unity project.

Running the demo server

Ensure you have Node v6+ installed. Then run these commands in your commandline:

cd Server
npm install
npm start


You'll need to start a coroutine for each WebSocket connection with the server. See usage example for more details.

Client colyseus = new Colyseus.Client ("ws://localhost:2657");

Room room = colyseus.Join ("room_name");
room.OnUpdate += OnUpdate;

Getting the full room state

void OnUpdate (object sender, RoomUpdateEventArgs e)
    if (e.isFirstState) {
        // First setup of your client state
    } else {
        // Further updates on your client state

Listening to add/remove on a specific key on the room state

room.Listen ("players/:id", OnPlayerChange);
void OnPlayerChange (DataChange change)
    Debug.Log (change.path["id"]);
    Debug.Log (change.operation); // "add" or "remove"
    Debug.Log (change.value); // the player object

Listening to specific data changes in the state

room.Listen ("players/:id/:axis", OnPlayerMove);
void OnPlayerMove (DataChange change)
    Debug.Log ("OnPlayerMove");
    Debug.Log ("playerId: " + change.path["id"] + ", axis: " + change.path["axis"]);
    Debug.Log (change.value);