UnityEngine.Networking.NetworkMigrationManager.Initialize C# (CSharp) Method

Initialize() public method

Used to initialize the migration manager with client and match information.

public Initialize ( NetworkClient newClient, MatchInfo newMatchInfo ) : void
newClient NetworkClient The NetworkClient being used to connect to the host.
newMatchInfo UnityEngine.Networking.Match.MatchInfo Information about the match being used. This may be null if there is no match.
return void
        public void Initialize(NetworkClient newClient, MatchInfo newMatchInfo)
        {
            if (LogFilter.logDev)
            {
                Debug.Log("NetworkMigrationManager initialize");
            }
            this.m_Client = newClient;
            this.m_MatchInfo = newMatchInfo;
            newClient.RegisterHandlerSafe(11, new NetworkMessageDelegate(this.OnPeerInfo));
            newClient.RegisterHandlerSafe(0x12, new NetworkMessageDelegate(this.OnPeerClientAuthority));
            NetworkIdentity.clientAuthorityCallback = new NetworkIdentity.ClientAuthorityCallback(this.AssignAuthorityCallback);
        }

Usage Example

Example #1
0
        public NetworkClient StartClient(MatchInfo info, ConnectionConfig config)
        {
            InitializeSingleton();

            matchInfo = info;
            if (m_RunInBackground)
            {
                Application.runInBackground = true;
            }

            isNetworkActive = true;

            if (m_GlobalConfig != null)
            {
                NetworkTransport.Init(m_GlobalConfig);
            }

            client = new NetworkClient();

            if (config != null)
            {
                if ((config.UsePlatformSpecificProtocols) && (UnityEngine.Application.platform != RuntimePlatform.PS4))
                {
                    throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
                }

                client.Configure(config, 1);
            }
            else
            {
                if (m_CustomConfig && m_ConnectionConfig != null)
                {
                    m_ConnectionConfig.Channels.Clear();
                    foreach (var c in m_Channels)
                    {
                        m_ConnectionConfig.AddChannel(c);
                    }
                    if ((m_ConnectionConfig.UsePlatformSpecificProtocols) && (UnityEngine.Application.platform != RuntimePlatform.PS4))
                    {
                        throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
                    }
                    client.Configure(m_ConnectionConfig, m_MaxConnections);
                }
            }

            RegisterClientMessages(client);
            if (matchInfo != null)
            {
                if (LogFilter.logDebug)
                {
                    Debug.Log("NetworkManager StartClient match: " + matchInfo);
                }
                client.Connect(matchInfo);
            }
            else if (m_EndPoint != null)
            {
                if (LogFilter.logDebug)
                {
                    Debug.Log("NetworkManager StartClient using provided SecureTunnel");
                }
                client.Connect(m_EndPoint);
            }
            else
            {
                if (string.IsNullOrEmpty(m_NetworkAddress))
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Must set the Network Address field in the manager");
                    }
                    return(null);
                }
                if (LogFilter.logDebug)
                {
                    Debug.Log("NetworkManager StartClient address:" + m_NetworkAddress + " port:" + m_NetworkPort);
                }

                if (m_UseSimulator)
                {
                    client.ConnectWithSimulator(m_NetworkAddress, m_NetworkPort, m_SimulatedLatency, m_PacketLossPercentage);
                }
                else
                {
                    client.Connect(m_NetworkAddress, m_NetworkPort);
                }
            }

#if ENABLE_UNET_HOST_MIGRATION
            if (m_MigrationManager != null)
            {
                m_MigrationManager.Initialize(client, matchInfo);
            }
#endif

            OnStartClient(client);
            s_Address = m_NetworkAddress;
            return(client);
        }