コード例 #1
0
 internal void SetPlayerController(QPlayerController player)
 {
     while (player.PlayerControllerId >= PlayerControllers.Count)
     {
         PlayerControllers.Add(new QPlayerController());
     }
     PlayerControllers[player.PlayerControllerId] = player;
 }
コード例 #2
0
 internal void RemovePlayerController(short playerControllerId)
 {
     for (var i = PlayerControllers.Count; i >= 0; i--)
     {
         if (playerControllerId == i && playerControllerId == PlayerControllers[i].PlayerControllerId)
         {
             PlayerControllers[i] = new QPlayerController();
             return;
         }
     }
     QLog.Error($"RemovePlayer player at playerControllerId {playerControllerId} not found");
 }
コード例 #3
0
        internal void AddLocalPlayer(QPlayerController localPlayer)
        {
            Debug.Log($"Local client AddLocalPlayer {localPlayer.Gameobject.name} conn={m_Connection.connectionId}");
            m_Connection.isReady = true;
            m_Connection.SetPlayerController(localPlayer);
            var unetView = localPlayer.UnetView;

            if (unetView != null)
            {
                QClientScene.SetLocalObject(unetView.NetId, localPlayer.Gameobject);
                unetView.SetConnectionToServer(m_Connection);
            }
            QClientScene.InternalAddPlayer(unetView, localPlayer.PlayerControllerId);
        }
コード例 #4
0
        internal static void InternalAddPlayer(QNetworkIdentity view, short playerControllerId)
        {
            Debug.LogWarning($"ClientScene::InternalAddPlayer: playerControllerId : {playerControllerId}");
            if (playerControllerId >= localPlayers.Count)
            {
                Debug.LogWarning(
                    $"ClientScene::InternalAddPlayer: playerControllerId higher than expected: {playerControllerId}");
                while (playerControllerId >= localPlayers.Count)
                {
                    localPlayers.Add(new QPlayerController());
                }
            }
            var playerController = new QPlayerController
            {
                Gameobject         = view.gameObject,
                PlayerControllerId = playerControllerId,
                UnetView           = view
            };

            localPlayers[playerControllerId] = playerController;
            readyConnection.SetPlayerController(playerController);
        }
コード例 #5
0
        internal static bool GetPlayerController(short playerControllerId, out QPlayerController player)
        {
            player = null;
            bool result;

            if (playerControllerId >= localPlayers.Count)
            {
                Debug.Log($"ClientScene::GetPlayer: no local player found for: {playerControllerId}");
                result = false;
            }
            else if (localPlayers[playerControllerId] == null)
            {
                Debug.LogWarning($"ClientScene::GetPlayer: local player is null for: {playerControllerId}");
                result = false;
            }
            else
            {
                player = localPlayers[playerControllerId];
                result = player.Gameobject != null;
            }
            return(result);
        }
コード例 #6
0
        internal bool GetPlayerController(short playerControllerId, out QPlayerController playerController)
        {
            playerController = null;
            bool result;

            if (PlayerControllers.Count > 0)
            {
                foreach (var controller in PlayerControllers)
                {
                    if (controller.IsValid && controller.PlayerControllerId == playerControllerId)
                    {
                        playerController = controller;
                        return(true);
                    }
                }

                result = false;
            }
            else
            {
                result = false;
            }
            return(result);
        }
コード例 #7
0
        public static bool RemovePlayer(short playerControllerId)
        {
            Debug.Log($"ClientScene::RemovePlayer() for ID {playerControllerId} called with connection [{readyConnection}]");
            bool result;

            if (readyConnection.GetPlayerController(playerControllerId, out var playerController))
            {
                var removePlayerMessage = new QRemovePlayerMessage
                {
                    PlayerControllerId = playerControllerId
                };
                readyConnection.Send(38, removePlayerMessage);
                readyConnection.RemovePlayerController(playerControllerId);
                localPlayers[playerControllerId] = new QPlayerController();
                Object.Destroy(playerController.Gameobject);
                result = true;
            }
            else
            {
                Debug.LogError($"Failed to find player ID {playerControllerId}");
                result = false;
            }
            return(result);
        }