UnityEngine.Networking.NetworkConnection.GetPlayerController C# (CSharp) Method

GetPlayerController() private method

private GetPlayerController ( short playerControllerId, PlayerController &playerController ) : bool
playerControllerId short
playerController PlayerController
return bool
        internal bool GetPlayerController(short playerControllerId, out PlayerController playerController)
        {
            playerController = null;
            if (this.playerControllers.Count > 0)
            {
                for (int i = 0; i < this.playerControllers.Count; i++)
                {
                    if (this.playerControllers[i].IsValid && (this.playerControllers[i].playerControllerId == playerControllerId))
                    {
                        playerController = this.playerControllers[i];
                        return true;
                    }
                }
                return false;
            }
            return false;
        }

Usage Example

コード例 #1
0
        public static bool AddPlayer(NetworkConnection readyConn, short playerControllerId, MessageBase extraMessage)
        {
            if (playerControllerId < 0)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("ClientScene::AddPlayer: playerControllerId of " + playerControllerId + " is negative");
                }
                return(false);
            }
            if (playerControllerId > 32)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("ClientScene::AddPlayer: playerControllerId of " + playerControllerId + " is too high, max is " + 32);
                }
                return(false);
            }
            if (playerControllerId > 16 && LogFilter.logWarn)
            {
                Debug.LogWarning("ClientScene::AddPlayer: playerControllerId of " + playerControllerId + " is unusually high");
            }
            while (playerControllerId >= s_LocalPlayers.Count)
            {
                s_LocalPlayers.Add(new PlayerController());
            }
            if (readyConn == null)
            {
                if (!s_IsReady)
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Must call AddPlayer() with a connection the first time to become ready.");
                    }
                    return(false);
                }
            }
            else
            {
                s_IsReady         = true;
                s_ReadyConnection = readyConn;
            }
            PlayerController playerController;

            if (s_ReadyConnection.GetPlayerController(playerControllerId, out playerController) && playerController.IsValid && playerController.gameObject != null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("ClientScene::AddPlayer: playerControllerId of " + playerControllerId + " already in use.");
                }
                return(false);
            }
            if (LogFilter.logDebug)
            {
                Debug.Log("ClientScene::AddPlayer() for ID " + playerControllerId + " called with connection [" + s_ReadyConnection + "]");
            }
            AddPlayerMessage addPlayerMessage = new AddPlayerMessage();

            addPlayerMessage.playerControllerId = playerControllerId;
            if (extraMessage != null)
            {
                NetworkWriter networkWriter = new NetworkWriter();
                extraMessage.Serialize(networkWriter);
                addPlayerMessage.msgData = networkWriter.ToArray();
                addPlayerMessage.msgSize = networkWriter.Position;
            }
            s_ReadyConnection.Send(37, addPlayerMessage);
            return(true);
        }
All Usage Examples Of UnityEngine.Networking.NetworkConnection::GetPlayerController