Skip to content

Commit 984a174

Browse files
authored
Merge pull request #191 from simon-winter/patch-2
docs(networking-manager): added NetworkingManager documentation
2 parents 95bc5f8 + f1537a8 commit 984a174

File tree

1 file changed

+43
-8
lines changed

1 file changed

+43
-8
lines changed

docs/_docs/core-components/networking-manager.md

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,46 @@ title: NetworkingManager
33
permalink: /wiki/networking-manager/
44
---
55

6-
<div class="panel panel-warning">
7-
<div class="panel-heading">
8-
<h3 class="panel-title"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> Not yet written</h3>
9-
</div>
10-
<div class="panel-body">
11-
This page is not yet written, or it's documentation is incomplete. The MLAPI is a community project, if you want to contribute to the documentation, please do so to benefit everyone
12-
</div>
13-
</div>
6+
The NetworkingManager is a script component handling all your Networking related settings, your Networked Prefabs and your registered scene names. A Transport component is needed on the same GameObject. It is responsible for handling IP adresses and additional settings.
7+
8+
### Starting a Server, Host or Client
9+
The NetworkingManager allows you to start/stop the Networking. It provides the same functions for Server, Host and Client.
10+
The Host functions as Server and Client simultaneously.
11+
```csharp
12+
NetworkingManager.Singleton.StartServer(); //or
13+
NetworkingManager.Singleton.StartHost(); //or
14+
NetworkingManager.Singleton.StartClient();
15+
```
16+
17+
### Connecting
18+
When Starting a Client, the NetworkingManager uses the IP and the Port provided in your "Transport" component for connecting.
19+
You can use different transports and have to replace the type inside the following GetComponent<> accordingly, but for UNET transport it looks like this:
20+
```csharp
21+
NetworkingManager.Singleton.GetComponent<UnetTransport>().ConnectAddress = "127.0.0.1"; //takes string
22+
NetworkingManager.Singleton.GetComponent<UnetTransport>().ConnectPort = 12345; //takes integer
23+
```
24+
25+
### Disconnecting
26+
Disconnecting is rather simple, but you have to remember, that you cannot use the ```NetworkSceneManager``` for scene switching in most Disconnecting cases. As soon as you stop the Client, Server or Host you have to use UnityEngine.SceneManagement instead.
27+
```csharp
28+
public void Disconnect()
29+
{
30+
if (IsHost)
31+
{
32+
NetworkingManager.Singleton.StopHost();
33+
}
34+
else if (IsClient)
35+
{
36+
NetworkingManager.Singleton.StopClient();
37+
}
38+
else if (IsServer)
39+
{
40+
NetworkingManager.Singleton.StopServer();
41+
}
42+
43+
UnityEngine.SceneManagement.SceneManager.LoadScene("MainMenu");
44+
}
45+
```
46+
47+
The only case where you could use the ```NetworkSceneManager``` for disconnecting, would be if the Server/Host switches back to MainMenu or similar for everyone and then Stopping the Server and all the Clients.
48+
(See ```NetworkSceneManager``` for more details).

0 commit comments

Comments
 (0)