private void GameFinished_Update() { if (m_GameFinishedTimedOut) { return; } // Sync time. if (!m_GameFinishedTimeSynced) { UpdateGameFinishedStartTime(); } // Update timer. double time = m_TimeForRematch; double startTime; bool startTimeAlreadySet = false; if (PhotonUtils.TryGetRoomCustomProperty <bool>(PhotonPropertyKey.s_RoomCustomPropertyKey_GameFinishedStartTimeAlreadySet, out startTimeAlreadySet)) { if (startTimeAlreadySet) { if (PhotonUtils.TryGetRoomCustomProperty <double>(PhotonPropertyKey.s_RoomCustomPropertyKey_GameFinishedStartTime, out startTime)) { m_GameFinishedTimeSynced = true; double elapsedTime = PhotonNetwork.time - startTime; time = m_TimeForRematch - elapsedTime; } } } time = Math.Max(time, 0.0); if (m_EndGamePanel != null) { m_EndGamePanel.SetTimer((float)time); } // Check time out. if (time <= 0.0) { OnTimedOut(); } }
public static bool GetPhotonPlayerOwnerId(int i_OnlinePlayerIndex, out int o_Id) { o_Id = -1; tnMultiplayerIndexTable indexTable = null; if (PhotonUtils.TryGetRoomCustomProperty <tnMultiplayerIndexTable>(PhotonPropertyKey.s_RoomCustomPropertyKey_AssignedIndices, out indexTable)) { if (indexTable != null) { int id = indexTable.GetIndexOwnerId(i_OnlinePlayerIndex); if (id != -1) { o_Id = id; return(true); } } } return(false); }
private void WaitForRematch_Update() { if (m_WaitForRematch_Success || m_WaitForRematch_Failed) { return; } if (m_PlayerDisconnectedAfterGameFinished || m_WaitForRematch_Failed) { if (m_WaitForRematch_QuitDialogOpened) { return; } // Set flag. m_WaitForRematch_QuitDialogOpened = true; // Clear all groups. ClearAllGroups(); // Clear Match controller UI. if (m_MatchController != null) { m_MatchController.ClearUI(); } // Open dialog. ShowDialog("MATCH OVER", "You will be returned to the main menu.", On_WaitForRematch_QuitDialogCallback); return; } // Sync time. if (!m_GameFinishedTimeSynced) { UpdateGameFinishedStartTime(); } // Update timer. double time = m_TimeForRematch; double startTime; if (PhotonUtils.TryGetRoomCustomProperty <double>(PhotonPropertyKey.s_RoomCustomPropertyKey_GameFinishedStartTime, out startTime)) { m_GameFinishedTimeSynced = true; double elapsedTime = PhotonNetwork.time - startTime; time = m_TimeForRematch - elapsedTime; } time = Math.Max(time, 0.0); if (m_EndGamePanel != null) { m_EndGamePanel.SetTimer((float)time); } // Check rematch. int totalVotes = 0; int rematchVotes = 0; int playerCount = 0; PhotonPlayer[] photonPlayers = PhotonNetwork.playerList; if (photonPlayers != null) { playerCount = photonPlayers.Length; for (int photonPlayerIndex = 0; photonPlayerIndex < photonPlayers.Length; ++photonPlayerIndex) { PhotonPlayer photonPlayer = photonPlayers[photonPlayerIndex]; if (photonPlayer == null) { continue; } bool voted; PhotonUtils.TryGetPlayerCustomProperty <bool>(photonPlayer, s_RematchVoted_PropertyKey, out voted); if (voted) { ++totalVotes; bool vote; PhotonUtils.TryGetPlayerCustomProperty <bool>(photonPlayer, s_RematchVote_PropertyKey, out vote); rematchVotes += (vote) ? 1 : 0; } } } if (m_EndGamePanel != null) { m_EndGamePanel.SetReadyPlayers(rematchVotes, playerCount); } if (playerCount > 1) { if (rematchVotes == playerCount) { m_WaitForRematch_Success = true; ProceedTo(tnMultiplayerGameState.RestartGame); } else { if (totalVotes == playerCount) { m_WaitForRematch_Failed = true; } } } else { m_WaitForRematch_Failed = true; } }
private void UpdateView() { if (viewInstance == null) { return; } ClearView(); int showedRooms = 0; for (int index = minShowedIndex; index >= 0 && index <= maxShowedIndex; ++index) { RoomInfo roomInfo = m_Rooms[index]; if (roomInfo == null) { continue; } int stadiumId; PhotonUtils.TryGetRoomCustomProperty <int>(roomInfo, PhotonPropertyKey.s_RoomCustomPropertyKey_Stadium, out stadiumId); int gameModeId; PhotonUtils.TryGetRoomCustomProperty <int>(roomInfo, PhotonPropertyKey.s_RoomCustomPropertyKey_GameMode, out gameModeId); int matchDurationOptionId; PhotonUtils.TryGetRoomCustomProperty <int>(roomInfo, PhotonPropertyKey.s_RoomCustomPropertyKey_MatchDuration, out matchDurationOptionId); int goldenGoalOptionId; PhotonUtils.TryGetRoomCustomProperty <int>(roomInfo, PhotonPropertyKey.s_RoomCustomPropertyKey_GoldenGoal, out goldenGoalOptionId); int refereeOptionId; PhotonUtils.TryGetRoomCustomProperty <int>(roomInfo, PhotonPropertyKey.s_RoomCustomPropertyKey_Referee, out refereeOptionId); string host; PhotonUtils.TryGetRoomCustomProperty <string>(roomInfo, PhotonPropertyKey.s_RoomCustomPropertyKey_HostName, out host); int playersCount; PhotonUtils.TryGetRoomCustomProperty <int>(roomInfo, PhotonPropertyKey.s_RoomCustomPropertyKey_PlayerCount, out playersCount); int ping; PhotonUtils.TryGetRoomCustomProperty <int>(roomInfo, PhotonPropertyKey.s_RoomCustomPropertyKey_AvgPing, out ping); int maxPlayer = roomInfo.MaxPlayers; Sprite stadiumThumbnail = null; string stadiumName = ""; string gameModeName = ""; string rules = ""; tnStadiumData stadiumData = tnGameData.GetStadiumDataMain(stadiumId); if (stadiumData != null) { stadiumThumbnail = stadiumData.icon; stadiumName = stadiumData.name; } tnGameModeData gameModeData = tnGameData.GetGameModeDataMain(gameModeId); if (gameModeData != null) { gameModeName = gameModeData.name; } float matchDuration; tnGameData.TryGetMatchDurationValueMain(matchDurationOptionId, out matchDuration); string matchDurationRule = TimeUtils.TimeToString(matchDuration, true, true); string goldenGoal; tnGameData.TryGetGoldenGoalValueMain(goldenGoalOptionId, out goldenGoal); string goldenGoalRule = (goldenGoal == "ON") ? "GOLDEN GOAL" : "NO GOLDEN GOAL"; string referee; tnGameData.TryGetRefereeValueMain(refereeOptionId, out referee); string refereeRule = (referee == "ON") ? "REFEREE" : ""; rules = goldenGoalRule + ", " + refereeRule + ((refereeRule == "") ? "" : ", ") + matchDurationRule; SetRoomData(showedRooms, stadiumThumbnail, stadiumName, gameModeName, rules, host, playersCount, maxPlayer, ping); ++showedRooms; } int roomsCount = m_Rooms.Count; float showedRoomsPercentage = (roomsCount > 0) ? (((float)showedRooms) / ((float)roomsCount)) : 1f; int slotCount = Mathf.Max(0, m_SlotsCount); int possibleStates = (roomsCount > slotCount) ? (roomsCount - slotCount) : 1; int currentStates = Mathf.Max(0, minShowedIndex); float positionPercentage = ((float)currentStates) / ((float)possibleStates); viewInstance.SetScrollbarHandleState(showedRoomsPercentage, positionPercentage); viewInstance.SetConfirmTriggerCanSend(roomsCount > 0); viewInstance.SetRefreshCommandActive(roomsCount > 0); }