mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
Remove NetworkClient/NetworkServer.NetworkConnectionClass magic
This commit is contained in:
parent
c87cd7b351
commit
245c94e6b1
@ -11,9 +11,8 @@ class ULocalConnectionToClient : NetworkConnection
|
||||
|
||||
public LocalClient localClient { get { return m_LocalClient; } }
|
||||
|
||||
public ULocalConnectionToClient(LocalClient localClient)
|
||||
public ULocalConnectionToClient(LocalClient localClient) : base ("localClient")
|
||||
{
|
||||
address = "localClient";
|
||||
m_LocalClient = localClient;
|
||||
}
|
||||
|
||||
@ -28,9 +27,8 @@ protected override bool SendBytes(byte[] bytes, int channelId = Channels.Default
|
||||
// send messages on this connection causes the server's handler function to be invoked directly.
|
||||
internal class ULocalConnectionToServer : NetworkConnection
|
||||
{
|
||||
public ULocalConnectionToServer()
|
||||
public ULocalConnectionToServer() : base("localServer")
|
||||
{
|
||||
address = "localServer";
|
||||
}
|
||||
|
||||
protected override bool SendBytes(byte[] bytes, int channelId = Channels.DefaultReliable)
|
||||
|
@ -8,8 +8,6 @@ namespace Mirror
|
||||
{
|
||||
public class NetworkClient
|
||||
{
|
||||
Type m_NetworkConnectionClass = typeof(NetworkConnection);
|
||||
|
||||
static bool s_IsActive;
|
||||
|
||||
public static List<NetworkClient> allClients = new List<NetworkClient>();
|
||||
@ -47,13 +45,6 @@ internal void SetHandlers(NetworkConnection conn)
|
||||
|
||||
public bool isConnected { get { return connectState == ConnectState.Connected; } }
|
||||
|
||||
public Type networkConnectionClass { get { return m_NetworkConnectionClass; } }
|
||||
|
||||
public void SetNetworkConnectionClass<T>() where T : NetworkConnection
|
||||
{
|
||||
m_NetworkConnectionClass = typeof(T);
|
||||
}
|
||||
|
||||
public NetworkClient()
|
||||
{
|
||||
if (LogFilter.Debug) { Debug.Log("Client created version " + Version.Current); }
|
||||
@ -86,9 +77,8 @@ public void Connect(string serverIp, ushort serverPort)
|
||||
Transport.layer.ClientConnect(serverIp, serverPort);
|
||||
|
||||
// setup all the handlers
|
||||
m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass);
|
||||
m_Connection = new NetworkConnection(m_ServerIp, m_ClientId, 0);
|
||||
m_Connection.SetHandlers(m_MessageHandlers);
|
||||
m_Connection.Initialize(m_ServerIp, m_ClientId, 0);
|
||||
}
|
||||
|
||||
void PrepareForConnect()
|
||||
|
@ -23,7 +23,11 @@ public class NetworkConnection : IDisposable
|
||||
public bool logNetworkMessages;
|
||||
public bool isConnected { get { return hostId != -1; }}
|
||||
|
||||
public virtual void Initialize(string networkAddress, int networkHostId, int networkConnectionId)
|
||||
public NetworkConnection(string networkAddress)
|
||||
{
|
||||
address = networkAddress;
|
||||
}
|
||||
public NetworkConnection(string networkAddress, int networkHostId, int networkConnectionId)
|
||||
{
|
||||
address = networkAddress;
|
||||
hostId = networkHostId;
|
||||
|
@ -34,13 +34,6 @@ public sealed class NetworkServer
|
||||
public static bool active { get { return s_Active; } }
|
||||
public static bool localClientActive { get { return s_LocalClientActive; } }
|
||||
|
||||
static Type s_NetworkConnectionClass = typeof(NetworkConnection);
|
||||
public static Type networkConnectionClass { get { return s_NetworkConnectionClass; } }
|
||||
public static void SetNetworkConnectionClass<T>() where T : NetworkConnection
|
||||
{
|
||||
s_NetworkConnectionClass = typeof(T);
|
||||
}
|
||||
|
||||
public static void Reset()
|
||||
{
|
||||
s_Active = false;
|
||||
@ -369,8 +362,7 @@ static void HandleConnect(int connectionId, byte error)
|
||||
Transport.layer.GetConnectionInfo(connectionId, out address);
|
||||
|
||||
// add player info
|
||||
NetworkConnection conn = (NetworkConnection)Activator.CreateInstance(s_NetworkConnectionClass);
|
||||
conn.Initialize(address, s_ServerHostId, connectionId);
|
||||
NetworkConnection conn = new NetworkConnection(address, s_ServerHostId, connectionId);
|
||||
AddConnection(conn);
|
||||
OnConnected(conn);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user