/*void OnDisable() * { * foreach (Transform child in playerScoreboardList) * { * Destroy(child.gameObject); * } * }*/ public NetworkInstanceId SpawnPlayerScore() { GameObject scoreBoardItem = (GameObject)Instantiate(playerScoreItem, playerScoreboardList); PlayerScoreItem item = scoreBoardItem.GetComponent <PlayerScoreItem>(); NetworkServer.Spawn(scoreBoardItem); if (scoreBoardItem != null) { scoreBoardItem.transform.parent = playerScoreboardList; } return(item.GetComponent <NetworkIdentity> ().netId); }
void OnEnable() { PlayerManager[] players = GameManager.GetAllPlayers(); foreach (PlayerManager player in players) { GameObject itemGO = (GameObject)Instantiate(playerScoreboardItem, playerScoreList); PlayerScoreItem item = itemGO.GetComponent <PlayerScoreItem> (); if (item != null) { item.Setup(player.username, player.kills.ToString(), player.deaths.ToString()); } } }
IEnumerator PostStartWait() { yield return(new WaitForSeconds(0.1f)); template = GetComponentInChildren <PlayerScoreItem>(); for (int i = 0; i < GameManager.instance.players.Count; ++i) { PlayerScoreItem playerScoreSub = (PlayerScoreItem)Instantiate(template, transform); playerScoreSub.SetName(GameManager.instance.players[i].playerName); scoreItems.Add(playerScoreSub); playerScoreSub.gameObject.name = "Player " + i.ToString(); } template.gameObject.SetActive(false); ready = true; }
List <PlayerScoreItem> Sort(List <PlayerScoreItem> list) { for (int i = 0; i < list.Count - 1; i++) { int index = i; PlayerScoreItem key = list[i]; for (int j = i + 1; j < list.Count; j++) { if (list[index].m_score < list[j].m_score) { index = j; } } if (index != i) { list[i] = list[index]; list[index] = key; } } return(list); }
public void InitScoreResult(ScoreModel scoreModel) { //初始化局分记录 if (names == null || names.Length == 0) { InitNames(); } Debug.Log("scoreModel.Round:" + scoreModel.Round); for (int i = 0; i < 4; i++) { Debug.Log(scoreModel.RoundOne[i + 1]); } for (int i = 1; i <= scoreModel.Round; i++) { Dictionary <int, int> dic = null; switch (i) { case 1: dic = scoreModel.RoundOne; break; case 2: dic = scoreModel.RoundTwo; break; case 3: dic = scoreModel.RoundThree; break; case 4: dic = scoreModel.RoundFour; break; } PlayerJFScoreItem JFItem = new PlayerJFScoreItem(); for (int j = 1; j <= 4; j++) { PlayerScoreItem item = new PlayerScoreItem(); item.m_name = names[j - 1]; if (dic != null) { item.m_score = dic[j]; } JFItem.m_PlayerItemList.Add(item); } JFItem.m_Count = i; Sort(JFItem.m_PlayerItemList); GameObject JF_GameObj = ResourcesMgr.m_Instance.GetGameObject("Prefab/MainScene/ResultScore/PlayerJF_Item"); if (PlayerJFGrid == null) { PlayerJFGrid = GetComponentInChildren <UIGrid>(); } JF_GameObj.GetComponent <PlayerJF_Item>().SetScore(JFItem); JF_GameObj.transform.SetParent(PLayerJF.transform); PlayerJFGrid.AddChild(JF_GameObj.transform); JF_GameObj.transform.localPosition = Vector3.zero; JF_GameObj.transform.localScale = Vector3.one; } PlayerJFGrid.Reposition(); PLayerJF.GetComponent <UIScrollView>().ResetPosition(); //玩家统计 PlayerJFScoreItem scoreItem = new PlayerJFScoreItem(); for (int i = 1; i <= 4; i++) { PlayerScoreItem item = new PlayerScoreItem(); item.m_name = names[i - 1]; item.m_score = scoreModel.GetTotal(i); scoreItem.m_PlayerItemList.Add(item); } Sort(scoreItem.m_PlayerItemList); PlayerTJ.GetComponent <PlayerJF_Item>().SetTotalScore(scoreItem); PLayerJF.SetActive(false); PlayerTJ.SetActive(true); }
public PlayerScoreSummary GetPlayerStatistics(int playerID) { var matches = _matchRepository.GetAllMatches(playerID); List <PlayerScoreItem> playerScores = matches.GroupBy(m => m.Player2ID).Select(lm => new PlayerScoreItem { PlayerID = lm.Key, Name = _playerRepository.GetPlayerName(lm.Key), GameWins = lm.Sum(m => m.Player1Wins), GameDraws = lm.Sum(m => m.Draws), GameLosses = lm.Sum(m => m.Player2Wins), MatchWins = lm.Count(m => ParseMatchResult(m) == MatchResult.Win), MatchLosses = lm.Count(m => ParseMatchResult(m) == MatchResult.Loss), MatchDraws = lm.Count(m => ParseMatchResult(m) == MatchResult.Draw) } ).ToList(); var totalScores = new PlayerScoreItem { PlayerID = 0, Name = "Total", GameWins = matches.Sum(m => m.Player1Wins), GameDraws = matches.Sum(m => m.Draws), GameLosses = matches.Sum(m => m.Player2Wins), MatchWins = matches.Count(m => ParseMatchResult(m) == MatchResult.Win), MatchLosses = matches.Count(m => ParseMatchResult(m) == MatchResult.Loss), MatchDraws = matches.Count(m => ParseMatchResult(m) == MatchResult.Draw) }; var topEightGroups = matches.Where(m => m.Round == 4).GroupBy(m => m.Event); var wins = 0; foreach (var group in topEightGroups) { if (group.All(m => m.HasWon(playerID))) { wins++; } } var leaguesUndefeatedSwissMatches = 0; var events = _eventRepository.LoadAllDBEvents(); var leagueGroups = matches.Where(m => ((m.Round == 1 || m.Round == 2 | m.Round == 3) && (m.Player1ID == playerID || m.Player2ID == playerID))).GroupBy(m => m.Event); foreach (var group in leagueGroups) { if (!group.All(m => m.Event == group.First().Event)) { throw new Exception("Group matches don't all meet expectations"); } var thisEvent = events.Single(e => e.Name == group.First().Event); var swissRounds = thisEvent.RoundMatches * thisEvent.Rounds; if (group.All(m => m.HasWon(playerID))) { leaguesUndefeatedSwissMatches += 1; } } var summary = new PlayerScoreSummary { OpponentScoreItems = playerScores, Totals = totalScores, LeagueTopEights = topEightGroups.Count(), LeagueWins = wins, LeaguesUndefeatedInMatches = leaguesUndefeatedSwissMatches }; return(summary); }