/// <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); }); }
/// <summary> /// Returns the next possible TeamID. /// </summary> public static TeamID GetNextTeam(TeamID team) { int newTeamID = (int)team; newTeamID %= TeamData.GetMaxTeams(PhotonNetwork.room.MaxPlayers); newTeamID++; return((TeamID)newTeamID); }
/// <summary> /// Initialises the class before Start. /// </summary> private new void Awake() { Team = TeamID.NoTeam; base.Awake(); Rigidbody2D rigidbody = gameObject.GetComponent <Rigidbody2D>(); rigidbody.isKinematic = true; m_PlayersOnPoint = new byte[TeamData.GetMaxTeams(PhotonNetwork.room.MaxPlayers)]; }
/// <summary> /// Returns the previous possible TeamID. /// </summary> public static TeamID GetPreviousTeam(TeamID team) { int newTeamID = (int)team - 2; if (newTeamID < 0) { newTeamID = TeamData.GetMaxTeams(PhotonNetwork.room.MaxPlayers); } return((TeamID)newTeamID); }
/// <summary>Needed to update the team lists when joining a room.</summary> /// <remarks>Called by PUN. See enum PhotonNetworkingMessage for an explanation.</remarks> public void OnJoinedRoom() { PlayersPerTeam = new Dictionary <TeamID, List <PhotonPlayer> >(); Array enumVals = Enum.GetValues(typeof(TeamID)); for (int i = 0; i < TeamData.GetMaxTeams(PhotonNetwork.room.MaxPlayers) + 1; i++) { PlayersPerTeam[(TeamID)enumVals.GetValue(i)] = new List <PhotonPlayer>(); } this.UpdateTeams(); }
public void UpdateTeams() { Array enumVals = Enum.GetValues(typeof(TeamID)); for (int i = 0; i < TeamData.GetMaxTeams(PhotonNetwork.room.MaxPlayers) + 1; i++) { PlayersPerTeam[(TeamID)enumVals.GetValue(i)].Clear(); } for (int i = 0; i < PhotonNetwork.playerList.Length; i++) { PhotonPlayer player = PhotonNetwork.playerList[i]; TeamID playerTeam = player.GetTeam(); PlayersPerTeam[playerTeam].Add(player); } }
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 } }); } }
/// <summary> /// Initialises the class. /// </summary> private void Start() { if (s_Singleton != null) { Destroy(this); return; } s_Singleton = this; m_AmountOfTeams = TeamData.GetMaxTeams(PhotonNetwork.room.MaxPlayers); MasterClientStart(); m_Treasures = new List <Treasure>(); m_NextMoneyUpdateTime = m_MoneyUpdateTimeInterval; m_GameLength = (int)PhotonNetwork.room.CustomProperties[RoomManager.RoomGameDurationProp]; #if (UNITY_EDITOR) Debug.Log("Game will take: " + m_GameLength + "seconds"); #endif }
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); }