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

ReconnectPlayerForConnection() public method

This re-establishes a player object with a client that is reconnected. It is similar to NetworkServer.AddPlayerForConnection(). The player game object will become the player object for the new connection.

public ReconnectPlayerForConnection ( NetworkConnection newConnection, GameObject oldPlayer, int oldConnectionId, short playerControllerId ) : bool
newConnection NetworkConnection The connection of the new client.
oldPlayer UnityEngine.GameObject The player object.
oldConnectionId int This client's connectionId on the old host.
playerControllerId short The playerControllerId of the player that is rejoining.
return bool
        public bool ReconnectPlayerForConnection(NetworkConnection newConnection, GameObject oldPlayer, int oldConnectionId, short playerControllerId)
        {
            if (!NetworkServer.active)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("ReconnectPlayerForConnection must have active server");
                }
                return false;
            }
            if (LogFilter.logDebug)
            {
                Debug.Log(string.Concat(new object[] { "ReconnectPlayerForConnection: oldConnId=", oldConnectionId, " player=", oldPlayer, " conn:", newConnection }));
            }
            if (!this.m_PendingPlayers.ContainsKey(oldConnectionId))
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("ReconnectPlayerForConnection oldConnId=" + oldConnectionId + " not found.");
                }
                return false;
            }
            oldPlayer.SetActive(true);
            NetworkServer.Spawn(oldPlayer);
            if (!NetworkServer.AddPlayerForConnection(newConnection, oldPlayer, playerControllerId))
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("ReconnectPlayerForConnection oldConnId=" + oldConnectionId + " AddPlayerForConnection failed.");
                }
                return false;
            }
            if (NetworkServer.localClientActive)
            {
                this.SendPeerInfo();
            }
            return true;
        }