Exemplo n.º 1
0
    private void Start()
    {
        _players    = PhotonNetwork.PlayerList;
        playerCount = _players.Length;
        scoreboard  = new LeaderBoardElement[playerCount];
        int i = 0;

        foreach (Photon.Realtime.Player player in _players)
        {
            scoreboard[i++] = new LeaderBoardElement(player.NickName, 0);
        }
        UpdateDisplay();
    }
Exemplo n.º 2
0
 public static void sortLeaderBoard(List <LeaderBoardElement> leaderboard)
 {
     for (int i = 0; i < leaderboard.Count; i++)
     {
         for (int j = i + 1; j < leaderboard.Count; j++)
         {
             if (leaderboard[j].score > leaderboard[i].score)
             {
                 //Swap
                 LeaderBoardElement tmp = leaderboard[i];
                 leaderboard[i] = leaderboard[j];
                 leaderboard[j] = tmp;
             }
         }
     }
 }
Exemplo n.º 3
0
    public void RankingUpdate(string nick, int score)
    {
        int i = FindIndex(nick);

        if (i == -1)
        {
            return;
        }
        scoreboard[i].score = score;
        while (i > 0 && scoreboard[i].score > scoreboard[i - 1].score)
        {
            LeaderBoardElement tmp = scoreboard[i];
            scoreboard[i]     = scoreboard[i - 1];
            scoreboard[i - 1] = tmp;
            i--;
        }

        UpdateDisplay();
    }
Exemplo n.º 4
0
    public void UpdateTop(List <PlayerData> playerDatas)
    {
        foreach (var playerObject in PlayerObjects)
        {
            Destroy(playerObject);
        }

        PlayerDatas = playerDatas;
        PlayerData data;

        for (int i = 0; i < playerDatas.Count; i++)
        {
            data = playerDatas[i];
            GameObject tmp = Instantiate(playerElement, playerElementParent.transform);
            PlayerObjects.Add(tmp);
            LeaderBoardElement leaderBoardElement = tmp.GetComponent <LeaderBoardElement>();
            leaderBoardElement.PlayerData          = data;
            leaderBoardElement.playerPosition.text = "#" + (i + 1);
        }
    }
Exemplo n.º 5
0
    private void DrawUI()
    {
        Transform[] childLBElements = LeaderboardPanel.GetComponentsInChildren <Transform>();
        foreach (Transform childObject in childLBElements)
        {
            if (!LeaderboardPanel.transform.IsChildOf(childObject.transform))
            {
                Destroy(childObject.gameObject);
            }
        }
        // Populate leaderboard
        for (int i = 0; i < scores.leaderboard.Count; i++)
        {
            GameObject         LBgameObject = Instantiate(LeaderboardItemPrefab);
            LeaderBoardElement LBelement    = LBgameObject.GetComponent <LeaderBoardElement>();
            LBelement.SetupElement(i + 1, scores.leaderboard[i]);
            LBelement.transform.SetParent(LeaderboardPanel.transform, false);
        }

        // Scroll to top
        LeaderboardScrollRect.verticalNormalizedPosition = 1f;
    }
Exemplo n.º 6
0
    // Method to update the Game Menu User Interface
    public void RedrawUI()
    {
        if (FB.IsLoggedIn)
        {
            // Swap GUI Header for a player after login
            HeaderLoggedIn.SetActive(true);
            HeaderNotLoggedIn.SetActive(false);

            // Show HighScore if we have one
            if (GameStateManager.HighScore > 0)
            {
                ScoreText.text = "Score: " + GameStateManager.HighScore.ToString();
            }

            //Set Coin and Bomb counters
            CoinText.text = GameStateManager.CoinBalance.ToString();
            BombText.text = GameStateManager.NumBombs.ToString();
        }

        if (GameStateManager.UserTexture != null && !string.IsNullOrEmpty(GameStateManager.Username))
        {
            // Update Profile Picture
            ProfilePic.enabled = true;
            ProfilePic.texture = GameStateManager.UserTexture;

            // Update Welcome Text
            WelcomeText.text = "Welcome " + GameStateManager.Username + "!";

            // Disable loading animation
            LoadingText.SetActive(false);
        }

        var scores = GameStateManager.Scores;

        if (GameStateManager.ScoresReady && scores.Count > 0)
        {
            // Clear out previous leaderboard
            Transform[] childLBElements = LeaderboardPanel.GetComponentsInChildren <Transform>();
            foreach (Transform childObject in childLBElements)
            {
                if (!LeaderboardPanel.transform.IsChildOf(childObject.transform))
                {
                    Destroy(childObject.gameObject);
                }
            }

            // Populate leaderboard
            for (int i = 0; i < scores.Count; i++)
            {
                GameObject         LBgameObject = Instantiate(LeaderboardItemPrefab) as GameObject;
                LeaderBoardElement LBelement    = LBgameObject.GetComponent <LeaderBoardElement>();
                LBelement.SetupElement(i + 1, scores[i]);
                LBelement.transform.SetParent(LeaderboardPanel.transform, false);
            }

            // Scroll to top
            LeaderboardScrollRect.verticalNormalizedPosition = 1f;
        }

        // Update PaymentPanel UI
        PaymentPanel.GetComponent <PaymentDialog>().UpdateUI();
    }