Example #1
0
        /// <summary>
        /// Initialises the class.
        /// </summary>
        private void Start()
        {
            _mStartGameBtn.onClick.AddListener(() =>
            {
                if (CurrentGame.Instance.HostingLoginToken != null || !CurrentGame.Instance.HostingLoginToken.Equals(""))
                {
                    if (_mLobbyPlayerList.childCount <= 4)
                    {
                        CurrentGame.Instance.gameDetail.maxPlayersPerTeam = TeamData.GetMaxPlayersPerTeam(4);
                        CurrentGame.Instance.gameDetail.maxTeams          = TeamData.GetMaxTeams(4);
                    }
                    else
                    {
                        CurrentGame.Instance.gameDetail.maxTeams          = TeamData.GetMaxTeams(playerObjects.Count);
                        CurrentGame.Instance.gameDetail.maxPlayersPerTeam = TeamData.GetMaxPlayersPerTeam(playerObjects.Count);
                    }
                }

                Debug.Log(CurrentGame.Instance.gameDetail.maxTeams + "= number of teams");
                Debug.Log(CurrentGame.Instance.gameDetail.maxPlayersPerTeam + "= number of players");

                // Adjust the number of teams and players
                Rest.ChangeTeams(CurrentGame.Instance.GameId, CurrentGame.Instance.HostingLoginToken, CurrentGame.Instance.gameDetail.maxTeams, CurrentGame.Instance.gameDetail.maxPlayersPerTeam);

                Rest.StartGame(CurrentGame.Instance.GameId, CurrentGame.Instance.HostingLoginToken);
            });
        }
Example #2
0
        public static void RequestTeam(this PhotonPlayer player)
        {
#if (UNITY_EDITOR)
            if (!PhotonNetwork.connectedAndReady)
            {
                Debug.LogWarning("JoinTeam was called in state: " + PhotonNetwork.connectionStateDetailed + ". Not connectedAndReady.");
                return;
            }
#endif

            TeamID newTeam       = player.GetTeam();
            int    maxIterations = TeamData.GetMaxTeams(PhotonNetwork.room.MaxPlayers);

            do
            {
                if (maxIterations <= 0)
                {
                    newTeam = TeamID.NotSet;
                    break;
                }
                maxIterations--;

                newTeam = TeamData.GetNextTeam(newTeam);
#if (UNITY_EDITOR)
                Debug.Log(newTeam);
#endif
            } while(RoomTeams.PlayersPerTeam[newTeam].Count >= TeamData.GetMaxPlayersPerTeam(PhotonNetwork.room.MaxPlayers));

            if (newTeam == TeamID.NotSet)
            {
#if (UNITY_EDITOR)
                Debug.Log("ERROR: No empty team found!");
#endif
            }
            else
            {
                player.SetCustomProperties(new Hashtable()
                {
                    { RoomTeams.TeamPlayerProp, (byte)newTeam }
                });
            }
        }
        public void MakeRoom()
        {
            CurrentGame.Instance.HostingLoginToken = Rest.DeviceLogin(CurrentGame.Instance.LocalPlayer.clientID);

            Debug.Log("hostinglogintoken: " + CurrentGame.Instance.HostingLoginToken);
            Debug.Log("roomname: " + _mRoomNameInp.text);
            Debug.Log("password: "******"Players: " + (int)_mRoomAmountOfPlayersSli.value);
            //int players = (int) _mRoomAmountOfPlayersSli.value;
            int players = MAX_NUMBER_PLAYERS;

            var gameId = Rest.NewGame(new GameResource(CurrentGame.Instance.HostingLoginToken, _mRoomNameInp.text, TeamData.GetMaxTeams(players), TeamData.GetMaxPlayersPerTeam(players), _mRoomPasswordInp.text));

            CurrentGame.Instance.HostedGameId = gameId;
            int minutes = 0;

            minutes = (int)GameDurationDropdown.m_Durations[_mRoomGameDurationDro.value].TotalMinutes;

            Rest.ChangeDuration(gameId, CurrentGame.Instance.HostingLoginToken, minutes);

            Debug.Log("gameid: " + gameId);

            EnableDisableMenu(false, "room");
            NetworkManager.Singleton.RoomManager.EnableDisableMenu(true, "room");
            NetworkManager.Singleton.LobbyManager.RegisterToGame(gameId, _mRoomPasswordInp.text);
        }