private void UpdateTeamList(CustomRoomOptions.Team team, ref List <PlayerListNode> teamNodeList, ref List <PhotonPlayer> playerList)
        {
            // Load player list form server.
            PhotonPlayer[] totalplayerList = PhotonNetwork.playerList;

            playerList.Clear();

            foreach (var player in totalplayerList)
            {
                if (CustomRoomOptions.GetTeam((int)player.customProperties[PlayerProperties.Team])
                    == team)
                {
                    playerList.Add(player);
                }
            }

            playerList.Sort(ComparerScore);

            for (int index = 0; index < teamNodeList.Count; index++)
            {
                if (index < playerList.Count)
                {
                    teamNodeList[index].ShowNode(true);
                    teamNodeList[index].SetInfo(playerList[index].isLocal,
                                                (index + 1).ToString(), playerList[index].name,
                                                (playerList[index].GetScore()));
                }
                else
                {
                    teamNodeList[index].ShowNode(false);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Check if the target team is full or not.
        /// </summary>
        /// <param name="team">The team you wanna check.</param>
        /// <returns>Return TRUE if team is full.</returns>
        public static bool CheckIfTeamFull(CustomRoomOptions.Team team)
        {
            PhotonPlayer[] playerlist      = PhotonNetwork.playerList;
            int            currentTeamSize = 0;

            foreach (var player in playerlist)
            {
                if (player.customProperties.ContainsKey(PlayerProperties.Team))
                {
                    // If the player's team is match with what we are looking for.
                    if (CustomRoomOptions.GetTeam((int)player.customProperties[PlayerProperties.Team]) == team)
                    {
                        currentTeamSize++;
                    }
                }
                else
                {
                    Debug.LogError("Player property TEAM is not exist.");
                    return(false);
                }
            }

            if (currentTeamSize >= (PhotonNetwork.room.maxPlayers / 2))
            {
                Debug.LogError("Any one side of team's menber should not more than half of the maximun player count.");
                return(false);
            }

            return(currentTeamSize == PhotonNetwork.room.maxPlayers);
        }
 public override void OnPlayerDisConnectedFormRoom(PhotonPlayer player)
 {
     if (CustomRoomOptions.GetTeam((int)player.customProperties[PlayerProperties.Team])
         == CustomRoomOptions.Team.Red)
     {
         UpdateTeamList(CustomRoomOptions.Team.Red, ref m_TeamRedNodeList, ref m_TeamRed);
     }
     else
     {
         UpdateTeamList(CustomRoomOptions.Team.Blue, ref m_TeamBlueNodeList, ref m_TeamBlue);
     }
 }
Example #4
0
 private void SyncTeam(int teamIndex, PhotonMessageInfo info)
 {
     Team = CustomRoomOptions.GetTeam(teamIndex);
 }