예제 #1
0
    // 새로운 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);
        }
    }
예제 #2
0
    void GetRanking()
    {
        if (!PlayFabClientAPI.IsClientLoggedIn())
        {
            Login(() => GetRanking());
            return;
        }

        GetLeaderboardRequest request = new GetLeaderboardRequest()
        {
            StatisticName   = "totalScore",
            StartPosition   = 0,
            MaxResultsCount = 100
        };

        PlayFabClientAPI.GetLeaderboard
        (
            request,
            result =>
        {
            rankUnits = new List <RankUnit>();
            result.Leaderboard.ForEach(entry =>
            {
                var unit = Instantiate(rankUnitPrefab, rankContentsParent);
                unit.Init(entry.Position + 1, entry.DisplayName, entry.StatValue);
                rankUnits.Add(unit);
                if (entry.PlayFabId == myID)
                {
                    myUnit = unit;
                }
            });
        },
            error => print(error.GenerateErrorReport())
        );
    }
예제 #3
0
    RankUnit AddRank()
    {
        GameObject sprite = Instantiate(unitSprite, Vector3.zero, Quaternion.identity) as GameObject;
        RankUnit   rank   = new RankUnit();

        rank.sprite   = sprite;
        rank.isLit    = false;
        rank.location = Vector3.zero;
        ranks[count]  = rank;
        count++;
        return(rank);
    }
예제 #4
0
    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);
        },
예제 #5
0
    public void Enter(int score = -1)
    {
        foreach (Transform unit in rankContentsParent)
        {
            Destroy(unit.gameObject);
        }
        rankUnits = null;
        myUnit    = null;

        lastScore = score;
        if (score != -1)
        {
            yourScore.Set(score);
        }

        GetRanking();
        GetYourHighScore();

        gameObject.SetActive(true);
        _IsActive.Value = true;
    }