leaderboard feature added
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using Darkmatter.Core;
|
||||
using System.Collections.Generic;
|
||||
using Unity.Services.Leaderboards;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
@@ -10,6 +12,10 @@ namespace Darkmatter.Presentation
|
||||
private const string leaderBoardID = "helix_leaderboard";
|
||||
private LeaderBoardView leaderBoardView;
|
||||
|
||||
|
||||
private List<LeaderBoardData> activeLBData = new List<LeaderBoardData>();
|
||||
[Inject] IPool<LeaderBoardData> leaderBoardDataPool;
|
||||
|
||||
public LeaderBoardController( LeaderBoardView _leaderBoardView )
|
||||
{
|
||||
this.leaderBoardView = _leaderBoardView;
|
||||
@@ -18,7 +24,13 @@ namespace Darkmatter.Presentation
|
||||
|
||||
private void OnExitBtnClicked()
|
||||
{
|
||||
Debug.Log("ExitBtnClicked From LeaderBoard");
|
||||
foreach(var lbData in activeLBData)
|
||||
{
|
||||
lbData.ResetData();
|
||||
leaderBoardDataPool.ReturnToPool(lbData);
|
||||
}
|
||||
activeLBData.Clear();
|
||||
leaderBoardView.Hide();
|
||||
}
|
||||
|
||||
public void ShowLeaderBoard()
|
||||
@@ -33,11 +45,29 @@ namespace Darkmatter.Presentation
|
||||
int rank = 1;
|
||||
foreach(var entry in score.Results)
|
||||
{
|
||||
leaderBoardView.UpdateData(rank,entry.PlayerName,entry.Score.ToString());
|
||||
LeaderBoardData LBData = leaderBoardDataPool.GetFromPool();
|
||||
|
||||
string playerID = PlayerPrefs.GetString("PlayerID");
|
||||
|
||||
if (entry.PlayerId == playerID)
|
||||
{
|
||||
LBData.BackgroundPanel.color = Color.yellow;
|
||||
LBData.playerName.text = "You";
|
||||
}
|
||||
else LBData.playerName.text = entry.PlayerName;
|
||||
|
||||
LBData.playerPos.text = rank.ToString();
|
||||
LBData.playerScore.text = entry.Score.ToString();
|
||||
activeLBData.Add(LBData); //adds the active data to the list
|
||||
rank++;
|
||||
}
|
||||
}
|
||||
|
||||
public async void UpdateLeaderBoardScore(int score)
|
||||
{
|
||||
await LeaderboardsService.Instance.AddPlayerScoreAsync(leaderBoardID, score);
|
||||
}
|
||||
|
||||
public void HideLeaderBoard()
|
||||
{
|
||||
leaderBoardView.Hide();
|
||||
|
||||
Reference in New Issue
Block a user