Network

Colyseus Unity3D



Patreon donate button Discussion forum

Multiplayer Game Client for Unity.
View documentation

Installation

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

Usage

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
		Debug.Log(e.state);
	} else {
		// Further updates on your client state
		Debug.Log(e.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);
}

License

MIT