Skip to content

binbytes/colyseus-unity3d

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation



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.OnStateChange += OnStateChange;

Getting the full room state

void OnStateChange (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

About

Multiplayer Game Client for Unity

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 99.7%
  • JavaScript 0.3%