mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
HostMode.cs - to move host mode connection setup out of NetworkClient
This commit is contained in:
parent
ca3bfed93a
commit
def22c864d
24
Assets/Mirror/Core/HostMode.cs
Normal file
24
Assets/Mirror/Core/HostMode.cs
Normal file
@ -0,0 +1,24 @@
|
||||
// host mode related helper functions.
|
||||
// usually they set up both server & client.
|
||||
// it's cleaner to keep them in one place, instead of only in server / client.
|
||||
namespace Mirror
|
||||
{
|
||||
internal static class HostMode
|
||||
{
|
||||
// keep the local connections setup in one function.
|
||||
// makes host setup easier to follow.
|
||||
internal static void SetupConnections()
|
||||
{
|
||||
// create local connections pair, both are connected
|
||||
Utils.CreateLocalConnections(
|
||||
out LocalConnectionToClient connectionToClient,
|
||||
out LocalConnectionToServer connectionToServer);
|
||||
|
||||
// set client connection
|
||||
NetworkClient.connection = connectionToServer;
|
||||
|
||||
// set server connection
|
||||
NetworkServer.SetLocalConnection(connectionToClient);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Mirror/Core/HostMode.cs.meta
Normal file
3
Assets/Mirror/Core/HostMode.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d27175a08d5341fc97645b49ee533d5a
|
||||
timeCreated: 1670849982
|
@ -212,29 +212,13 @@ public static void Connect(Uri uri)
|
||||
connection = new NetworkConnectionToServer();
|
||||
}
|
||||
|
||||
// keep the local connections setup in one function.
|
||||
// makes host setup easier to follow.
|
||||
// TODO this doesn't need to be in NetworkClient. it sets up both cl/sv.
|
||||
internal static void SetupHostConnections()
|
||||
{
|
||||
// create local connections pair, both are connected
|
||||
Utils.CreateLocalConnections(
|
||||
out LocalConnectionToClient connectionToClient,
|
||||
out LocalConnectionToServer connectionToServer);
|
||||
|
||||
connection = connectionToServer;
|
||||
|
||||
// create server connection to local client
|
||||
NetworkServer.SetLocalConnection(connectionToClient);
|
||||
}
|
||||
|
||||
// TODO why are there two connect host methods?
|
||||
// called from NetworkManager.FinishStartHost()
|
||||
public static void ConnectHost()
|
||||
{
|
||||
Initialize(true);
|
||||
connectState = ConnectState.Connected;
|
||||
SetupHostConnections();
|
||||
HostMode.SetupConnections();
|
||||
}
|
||||
|
||||
/// <summary>Connect host mode</summary>
|
||||
|
Loading…
Reference in New Issue
Block a user