Esempio n. 1
0
        /// <summary>
        /// Update button color and text
        /// </summary>
        public void UpdateButton()
        {
            assignedPlayer = null;
            for (int i = 0; i < PhotonNetwork.playerList.Length; i++)
            {
                PhotonPlayer  player     = PhotonNetwork.playerList[i];
                PunTeams.Team playerTeam = player.GetTeam();
                PunTeams.Role playerRole = player.GetRole();

                if ((playerTeam == team) && (playerRole == role))
                {
                    assignedPlayer = player;
                    break;
                }
            }

            if (assignedPlayer != null)
            {
                image.color = Color.red;
                text.text   = assignedPlayer.NickName;
            }
            else
            {
                image.color = Color.green;
                text.text   = "<empty>";
            }
        }
Esempio n. 2
0
    /// <summary>Switch that player's team to the one you assign.</summary>
    /// <remarks>Internally checks if this player is in that team already or not. Only team switches are actually sent.</remarks>
    /// <param name="player"></param>
    /// <param name="team"></param>
    public static void SetRole(this PhotonPlayer player, PunTeams.Role role)
    {
        if (!PhotonNetwork.connectedAndReady)
        {
            Debug.LogWarning("JoinTeam was called in state: " + PhotonNetwork.connectionStateDetailed + ". Not connectedAndReady.");
            return;
        }

        PunTeams.Role currentRole = player.GetRole();
        if (currentRole != role)
        {
            player.SetCustomProperties(new Hashtable()
            {
                { PunTeams.RolePlayerProp, (byte)role }
            });
        }
    }
Esempio n. 3
0
    public bool JoinTeam(PhotonPlayer currentPlayer, Team team, Role role)
    {
        bool positionAvailable = true;

        for (int i = 0; i < PhotonNetwork.playerList.Length; i++)
        {
            PhotonPlayer player = PhotonNetwork.playerList[i];
            if ((player.GetTeam() == team) && (player.GetRole() == role))
            {
                positionAvailable = false;
            }
        }

        if (positionAvailable)
        {
            currentPlayer.SetTeam(team);
            currentPlayer.SetRole(role);
            UpdateTeams();
            return(true);
        }

        return(false);
    }