SetPlayerController() private method

private SetPlayerController ( PlayerController player ) : void
player PlayerController
return void
        // this is called from message handler for Owner message
        internal static void InternalAddPlayer(NetworkIdentity view, short playerControllerId)
        {
            if (LogFilter.logDebug)
            {
                Debug.LogWarning("ClientScene::InternalAddPlayer: playerControllerId : " + playerControllerId);
            }

            if (playerControllerId >= s_LocalPlayers.Count)
            {
                if (LogFilter.logWarn)
                {
                    Debug.LogWarning("ClientScene::InternalAddPlayer: playerControllerId higher than expected: " + playerControllerId);
                }
                while (playerControllerId >= s_LocalPlayers.Count)
                {
                    s_LocalPlayers.Add(new PlayerController());
                }
            }

            // NOTE: It can be "normal" when changing scenes for the player to be destroyed and recreated.
            // But, the player structures are not cleaned up, we'll just replace the old player
            var newPlayer = new PlayerController {
                gameObject = view.gameObject, playerControllerId = playerControllerId, unetView = view
            };

            s_LocalPlayers[playerControllerId] = newPlayer;
            s_ReadyConnection.SetPlayerController(newPlayer);
        }
コード例 #2
0
        internal static void InternalAddPlayer(NetworkIdentity view, short playerControllerId)
        {
            if (LogFilter.logDebug)
            {
                Debug.LogWarning("ClientScene::InternalAddPlayer: playerControllerId : " + playerControllerId);
            }
            if (playerControllerId >= s_LocalPlayers.Count)
            {
                if (LogFilter.logWarn)
                {
                    Debug.LogWarning("ClientScene::InternalAddPlayer: playerControllerId higher than expected: " + playerControllerId);
                }
                while (playerControllerId >= s_LocalPlayers.Count)
                {
                    s_LocalPlayers.Add(new PlayerController());
                }
            }
            PlayerController playerController = new PlayerController();

            playerController.gameObject         = view.gameObject;
            playerController.playerControllerId = playerControllerId;
            playerController.unetView           = view;
            PlayerController playerController2 = playerController;

            s_LocalPlayers[playerControllerId] = playerController2;
            s_ReadyConnection.SetPlayerController(playerController2);
        }
コード例 #3
0
 internal bool InternalReplacePlayerForConnection(NetworkConnection conn, GameObject playerGameObject, short playerControllerId)
 {
     NetworkIdentity view;
       if (!NetworkServer.GetNetworkIdentity(playerGameObject, out view))
       {
     if (LogFilter.logError)
       Debug.LogError((object) ("ReplacePlayer: playerGameObject has no NetworkIdentity. Please add a NetworkIdentity to " + (object) playerGameObject));
     return false;
       }
       if (!this.CheckPlayerControllerIdForConnection(conn, playerControllerId))
     return false;
       if (LogFilter.logDev)
     Debug.Log((object) "NetworkServer ReplacePlayer");
       PlayerController playerController = new PlayerController(playerGameObject, playerControllerId);
       conn.SetPlayerController(playerController);
       view.m_PlayerId = playerController.playerControllerId;
       view.SetConnectionToClient(conn);
       if (LogFilter.logDev)
     Debug.Log((object) "NetworkServer ReplacePlayer setup local");
       if (this.SetupLocalPlayerForConnection(conn, view, playerController))
     return true;
       if (LogFilter.logDebug)
       {
     object[] objArray = new object[4];
     int index1 = 0;
     string str1 = "Replacing playerGameObject object netId: ";
     objArray[index1] = (object) str1;
     int index2 = 1;
     // ISSUE: variable of a boxed type
     __Boxed<NetworkInstanceId> local1 = (ValueType) playerGameObject.GetComponent<NetworkIdentity>().netId;
     objArray[index2] = (object) local1;
     int index3 = 2;
     string str2 = " asset ID ";
     objArray[index3] = (object) str2;
     int index4 = 3;
     // ISSUE: variable of a boxed type
     __Boxed<NetworkHash128> local2 = (ValueType) playerGameObject.GetComponent<NetworkIdentity>().assetId;
     objArray[index4] = (object) local2;
     Debug.Log((object) string.Concat(objArray));
       }
       this.FinishPlayerForConnection(conn, view, playerGameObject);
       return true;
 }
コード例 #4
0
 internal bool InternalAddPlayerForConnection(NetworkConnection conn, GameObject playerGameObject, short playerControllerId)
 {
     NetworkIdentity view;
       if (!NetworkServer.GetNetworkIdentity(playerGameObject, out view))
       {
     if (LogFilter.logError)
       Debug.Log((object) ("AddPlayer: playerGameObject has no NetworkIdentity. Please add a NetworkIdentity to " + (object) playerGameObject));
     return false;
       }
       if (!this.CheckPlayerControllerIdForConnection(conn, playerControllerId))
     return false;
       PlayerController playerController1 = (PlayerController) null;
       GameObject gameObject = (GameObject) null;
       if (conn.GetPlayerController(playerControllerId, out playerController1))
     gameObject = playerController1.gameObject;
       if ((UnityEngine.Object) gameObject != (UnityEngine.Object) null)
       {
     if (LogFilter.logError)
       Debug.Log((object) ("AddPlayer: player object already exists for playerControllerId of " + (object) playerControllerId));
     return false;
       }
       PlayerController playerController2 = new PlayerController(playerGameObject, playerControllerId);
       conn.SetPlayerController(playerController2);
       view.m_PlayerId = playerController2.playerControllerId;
       view.SetConnectionToClient(conn);
       NetworkServer.SetClientReady(conn);
       if (this.SetupLocalPlayerForConnection(conn, view, playerController2))
     return true;
       if (LogFilter.logDebug)
       {
     object[] objArray = new object[4];
     int index1 = 0;
     string str1 = "Adding new playerGameObject object netId: ";
     objArray[index1] = (object) str1;
     int index2 = 1;
     // ISSUE: variable of a boxed type
     __Boxed<NetworkInstanceId> local1 = (ValueType) playerGameObject.GetComponent<NetworkIdentity>().netId;
     objArray[index2] = (object) local1;
     int index3 = 2;
     string str2 = " asset ID ";
     objArray[index3] = (object) str2;
     int index4 = 3;
     // ISSUE: variable of a boxed type
     __Boxed<NetworkHash128> local2 = (ValueType) playerGameObject.GetComponent<NetworkIdentity>().assetId;
     objArray[index4] = (object) local2;
     Debug.Log((object) string.Concat(objArray));
       }
       this.FinishPlayerForConnection(conn, view, playerGameObject);
       return true;
 }
コード例 #5
0
 internal bool InternalReplacePlayerForConnection(NetworkConnection conn, GameObject playerGameObject, short playerControllerId)
 {
     NetworkIdentity identity;
     PlayerController controller;
     if (!GetNetworkIdentity(playerGameObject, out identity))
     {
         if (LogFilter.logError)
         {
             Debug.LogError("ReplacePlayer: playerGameObject has no NetworkIdentity. Please add a NetworkIdentity to " + playerGameObject);
         }
         return false;
     }
     if (!CheckPlayerControllerIdForConnection(conn, playerControllerId))
     {
         return false;
     }
     if (LogFilter.logDev)
     {
         Debug.Log("NetworkServer ReplacePlayer");
     }
     if (conn.GetPlayerController(playerControllerId, out controller))
     {
         controller.unetView.SetNotLocalPlayer();
         controller.unetView.ClearClientOwner();
     }
     PlayerController player = new PlayerController(playerGameObject, playerControllerId);
     conn.SetPlayerController(player);
     identity.SetConnectionToClient(conn, player.playerControllerId);
     if (LogFilter.logDev)
     {
         Debug.Log("NetworkServer ReplacePlayer setup local");
     }
     if (!this.SetupLocalPlayerForConnection(conn, identity, player))
     {
         if (LogFilter.logDebug)
         {
             Debug.Log(string.Concat(new object[] { "Replacing playerGameObject object netId: ", playerGameObject.GetComponent<NetworkIdentity>().netId, " asset ID ", playerGameObject.GetComponent<NetworkIdentity>().assetId }));
         }
         FinishPlayerForConnection(conn, identity, playerGameObject);
         if (identity.localPlayerAuthority)
         {
             identity.SetClientOwner(conn);
         }
     }
     return true;
 }
コード例 #6
0
 internal bool InternalAddPlayerForConnection(NetworkConnection conn, GameObject playerGameObject, short playerControllerId)
 {
     NetworkIdentity identity;
     if (!GetNetworkIdentity(playerGameObject, out identity))
     {
         if (LogFilter.logError)
         {
             Debug.Log("AddPlayer: playerGameObject has no NetworkIdentity. Please add a NetworkIdentity to " + playerGameObject);
         }
         return false;
     }
     if (!CheckPlayerControllerIdForConnection(conn, playerControllerId))
     {
         return false;
     }
     PlayerController playerController = null;
     GameObject gameObject = null;
     if (conn.GetPlayerController(playerControllerId, out playerController))
     {
         gameObject = playerController.gameObject;
     }
     if (gameObject != null)
     {
         if (LogFilter.logError)
         {
             Debug.Log("AddPlayer: player object already exists for playerControllerId of " + playerControllerId);
         }
         return false;
     }
     PlayerController player = new PlayerController(playerGameObject, playerControllerId);
     conn.SetPlayerController(player);
     identity.SetConnectionToClient(conn, player.playerControllerId);
     SetClientReady(conn);
     if (!this.SetupLocalPlayerForConnection(conn, identity, player))
     {
         if (LogFilter.logDebug)
         {
             Debug.Log(string.Concat(new object[] { "Adding new playerGameObject object netId: ", playerGameObject.GetComponent<NetworkIdentity>().netId, " asset ID ", playerGameObject.GetComponent<NetworkIdentity>().assetId }));
         }
         FinishPlayerForConnection(conn, identity, playerGameObject);
         if (identity.localPlayerAuthority)
         {
             identity.SetClientOwner(conn);
         }
     }
     return true;
 }