|
17 | 17 | <img src="https://img.shields.io/discord/525739117951320081.svg?style=for-the-badge&colorB=7581dc&logo=discord&logoColor=white">
|
18 | 18 | </a>
|
19 | 19 | <h3>
|
20 |
| - Multiplayer Game Client for <a href="https://unity3d.com/">Unity</a>. <br /><a href="http://colyseus.io/docs/">View documentation</a> |
| 20 | + Multiplayer Game Client for <a href="https://unity3d.com/">Unity</a>. <br /><a href="https://docs.colyseus.io/getting-started/unity3d-client/">View documentation</a> |
21 | 21 | </h3>
|
22 | 22 | </div>
|
23 | 23 |
|
24 |
| -## Installation |
25 |
| - |
26 |
| -Copy `Assets/Plugins` into your Unity project. |
27 |
| - |
28 |
| -## Running the demo server |
29 |
| - |
30 |
| -Ensure you have [Node v6+](http://nodejs.org/) installed. Then run these |
31 |
| -commands in your commandline: |
32 |
| - |
33 |
| -``` |
34 |
| -cd Server |
35 |
| -npm install |
36 |
| -npm start |
37 |
| -``` |
38 |
| - |
39 |
| -## Usage |
40 |
| - |
41 |
| -You'll need to start a coroutine for each WebSocket connection with the server. |
42 |
| -See [usage example](Assets/ColyseusClient.cs) for more details. |
43 |
| - |
44 |
| -```csharp |
45 |
| -Client colyseus = new Colyseus.Client ("ws://localhost:2657"); |
46 |
| - |
47 |
| -Room room = colyseus.Join ("room_name"); |
48 |
| -room.OnStateChange += OnStateChange; |
49 |
| -``` |
50 |
| - |
51 |
| -**Getting the full room state** |
52 |
| - |
53 |
| -```csharp |
54 |
| -void OnStateChange (object sender, RoomUpdateEventArgs e) |
55 |
| -{ |
56 |
| - if (e.isFirstState) { |
57 |
| - // First setup of your client state |
58 |
| - Debug.Log(e.state); |
59 |
| - } else { |
60 |
| - // Further updates on your client state |
61 |
| - Debug.Log(e.state); |
62 |
| - } |
63 |
| -} |
64 |
| -``` |
65 |
| - |
66 |
| -**Listening to add/remove on a specific key on the room state** |
67 |
| - |
68 |
| -```csharp |
69 |
| -room.Listen ("players/:id", OnPlayerChange); |
70 |
| -``` |
71 |
| - |
72 |
| -```csharp |
73 |
| -void OnPlayerChange (DataChange change) |
74 |
| -{ |
75 |
| - Debug.Log (change.path["id"]); |
76 |
| - Debug.Log (change.operation); // "add" or "remove" |
77 |
| - Debug.Log (change.value); // the player object |
78 |
| -} |
79 |
| -``` |
80 |
| - |
81 |
| -**Listening to specific data changes in the state** |
82 |
| - |
83 |
| -```csharp |
84 |
| -room.Listen ("players/:id/:axis", OnPlayerMove); |
85 |
| -``` |
86 |
| - |
87 |
| -```csharp |
88 |
| -void OnPlayerMove (DataChange change) |
89 |
| -{ |
90 |
| - Debug.Log ("OnPlayerMove"); |
91 |
| - Debug.Log ("playerId: " + change.path["id"] + ", axis: " + change.path["axis"]); |
92 |
| - Debug.Log (change.value); |
93 |
| -} |
94 |
| -``` |
95 |
| - |
96 | 24 | ## License
|
97 | 25 |
|
98 | 26 | MIT
|
0 commit comments