// 새로운 RankUnit 생성하여 추가. void AddNewRankUnit(int startIndex, int endIndex) { int rank = startIndex + 1; int continueRankNo = rank; for (int i = startIndex; i < endIndex; ++i) { // 프리팹 생성. GameObject makeRankUnit = Instantiate(rankUnitObj, rankAddRoot.position, Quaternion.identity) as GameObject; makeRankUnit.gameObject.name = (tempFriendList[i].state == 2) ? string.Format("Rank{0:000}", i + 1) : "Rank000"; makeRankUnit.transform.parent = rankAddRoot; makeRankUnit.transform.localScale = Vector3.one; makeRankUnit.transform.localPosition = Vector3.zero; // 점수가 같다면 순위 유지. rank = (preScore != tempFriendList[i].score) ? continueRankNo : rank; preScore = tempFriendList[i].score; ++continueRankNo; // RankUnit 초기화. RankUnit rankUnit = makeRankUnit.GetComponent <RankUnit>(); rankUnit.Init(tempFriendList[i], rank, (tempFriendList[i].state == -1)); rankList.Add(rankUnit); } }
void SendScore(int score, string name) { if (!PlayFabClientAPI.IsClientLoggedIn()) { Login(() => SendScore(score, name)); return; } UpdatePlayerStatisticsRequest request = new UpdatePlayerStatisticsRequest() { Statistics = new List <StatisticUpdate>() { new StatisticUpdate() { StatisticName = "totalScore", Value = score } } }; PlayFabClientAPI.UpdatePlayerStatistics ( request, result => { var below = rankUnits.FirstOrDefault(unit => unit.Score <= score); int index = (below is null) ? rankUnits.Count : below.transform.GetSiblingIndex(); if (myUnit is null) { myUnit = Instantiate(rankUnitPrefab, rankContentsParent); myUnit.Init(index + 1, name, score); rankUnits.Skip(index).ForEach(unit => unit.Rank++); } else { rankUnits.Remove(myUnit); int oldRank = myUnit.Rank; myUnit.Rank = index + 1; myUnit.Name = name; myUnit.Score = score; rankUnits.Take(oldRank - 1).Skip(index).ForEach(unit => unit.Rank++); } myUnit.transform.SetSiblingIndex(index); rankUnits.Insert(index, myUnit); bestScore = score; highScore.Set(bestScore); },