Skip to content

Commit

Permalink
Merge pull request #61 from colyseus/fix-issue-147
Browse files Browse the repository at this point in the history
Clarified protected connection call along with some Server Connection clarification and better explanations
  • Loading branch information
mitchLucid authored May 11, 2021
2 parents e25023b + 99c08ca commit 1ba242a
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions docs/getting-started/unity3d-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,24 @@ The built-in demonstration comes with a single [room handler](https://github.com
public class ExampleManager : ColyseusManager<ExampleManager>
```
- Make an in-scene manager object to host your custom Manager script.
- Provide your Manager with a reference to your Colyseus Settings object in the scene inspector.

## Connecting to Your Colyseus Server:

- In order to connect to your server you first need to provide your Manager a reference to your Colyseus Settings object in the scene inspector.
- Call `ConnectToServer()` of your Manager to initiate a server connection:
## Client:

- Call the `InitializeClient()` method of your Manager to create a `ColyseusClient` object which is stored in the `client` variable of `ColyseusManager`. This will be used to create/join rooms and form a connection with the server.
```csharp
ExampleManager.Instance.ConnectToServer();
ExampleManager.Instance.InitializeClient();
```
- If your Manager has additional classes that need reference to your `Client`, you can override `InitializeClient` and make those connections in there.
```csharp
//In ExampleManager.cs
public override void InitializeClient()
{
base.InitializeClient();
//Pass the newly created Client reference to our RoomController
_roomController.SetClient(client);
}
```

## Client:

- When you connect to the server an instance of `ColyseusClient` is created and is stored in the `client` variable of `ColyseusManager`.
- You can get available rooms on the server by calling `GetAvailableRooms` of `ColyseusClient`:
```csharp
return await GetAvailableRooms<ColyseusRoomAvailable>(roomName, headers);
Expand Down Expand Up @@ -170,6 +175,7 @@ room.Send("createEntity", new EntityCreationMessage() { creationId = creationId,
```

### Room State:
> See how to generate your `RoomState` from [State Handling](https://docs.colyseus.io/state/schema/#client-side-schema-generation)
- Each room holds its own state. The mutations of the state are synchronized automatically to all connected clients.
- In regards to room state synchronization:
- When the user successfully joins the room, they receive the full state from the server.
Expand Down

0 comments on commit 1ba242a

Please sign in to comment.