Leader board screen is added

posted in: Weekly Progress | 0

Leader board is added to show top 20 highest score of the users who are playing all around the world.

 

here is the code

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.IO;
using System.Text;
using UnityEngine.UI;

public class LeaderBoardManager : MonoBehaviour
{
public static LeaderBoardManager Instance {get; private set;}
public GameObject GlobalLeaderboardPanel;

public Text NameLabel1;
public Text NameLabel2;
public Text NameLabel3;
public Text NameLabel4;
public Text NameLabel5;
public Text NameLabel6;
public Text NameLabel7;
public Text NameLabel8;
public Text NameLabel9;
public Text NameLabel10;
public Text NameLabel11;
public Text NameLabel12;
public Text NameLabel13;
public Text NameLabel14;
public Text NameLabel15;
public Text NameLabel16;
public Text NameLabel17;
public Text NameLabel18;
public Text NameLabel19;
public Text NameLabel20;
public Text HighScoreLabel1;
public Text HighScoreLabel2;
public Text HighScoreLabel3;
public Text HighScoreLabel4;
public Text HighScoreLabel5;
public Text HighScoreLabel6;
public Text HighScoreLabel7;
public Text HighScoreLabel8;
public Text HighScoreLabel9;
public Text HighScoreLabel10;
public Text HighScoreLabel11;
public Text HighScoreLabel12;
public Text HighScoreLabel13;
public Text HighScoreLabel14;
public Text HighScoreLabel15;
public Text HighScoreLabel16;
public Text HighScoreLabel17;
public Text HighScoreLabel18;
public Text HighScoreLabel19;
public Text HighScoreLabel20;
public string[] UserProfileArray;
public int Count;

void Awake()
{
Instance = this;
Count = 20;
}

public void Start()
{
if( (GameManager.Instance.GetPlatform() != GameManager.ePlatform.Platform_KONGREGATE) || (GameManager.Instance.GetPlatform() != GameManager.ePlatform.Platform_FACEBOOK))
{
DBManager.Instance.UpdateHighScore(ProfileManager.Instance.ProSettings.Name,ProfileManager.Instance.ProSettings.FinalNameAndKey , ProfileManager.Instance.ProSettings.HighestScore, true);

LeaderBoardManager.Instance.GetHighScoreList();
}
}

public bool GetHighScoreList()
{
if(DBManager.Instance.GetPlayerAttribute(true) != DBManager.gdbStatusCode.Success)
return false;

return true;
}

public void ShowGlobalLeaderBoard()
{
if( (GameManager.Instance.GetPlatform() == GameManager.ePlatform.Platform_FACEBOOK) || (GameManager.Instance.GetPlatform() == GameManager.ePlatform.Platform_KONGREGATE))
return;

int EntriesCount = int.Parse(UserProfileArray[2]);
DBManager.PlayerInfoDB temp = new DBManager.PlayerInfoDB();

int indexOfName = 8;
int indexOfScore = 12;
int NextindexOffset = 10;

for (int i = 0; i < Count && i < EntriesCount; i++)
{
temp.PlayerName = UserProfileArray[indexOfName];
temp.Score = int.Parse(UserProfileArray[indexOfScore]);
DBManager.Instance.AddPlayerToList(temp);

Debug.Log(“name is … ” + temp.PlayerName);
Debug.Log(“score is ….” + temp.Score);

if (i == 0)
{
NameLabel1.text = temp.PlayerName;
HighScoreLabel1.text = temp.Score.ToString();
}
else if (i == 1)
{
NameLabel2.text = temp.PlayerName;
HighScoreLabel2.text = temp.Score.ToString();
}
else if (i == 2)
{
NameLabel3.text = temp.PlayerName;
HighScoreLabel3.text = temp.Score.ToString();
}
else if (i == 3)
{
NameLabel4.text = temp.PlayerName;
HighScoreLabel4.text = temp.Score.ToString();
}
else if (i == 4)
{
NameLabel5.text = temp.PlayerName;
HighScoreLabel5.text = temp.Score.ToString();
}
else if (i == 5)
{
NameLabel6.text = temp.PlayerName;
HighScoreLabel6.text = temp.Score.ToString();
}
else if (i == 6)
{
NameLabel7.text = temp.PlayerName;
HighScoreLabel7.text = temp.Score.ToString();
}
else if (i == 7)
{
NameLabel8.text = temp.PlayerName;
HighScoreLabel8.text = temp.Score.ToString();
}
else if (i == 8)
{
NameLabel9.text = temp.PlayerName;
HighScoreLabel9.text = temp.Score.ToString();
}
else if (i == 9)
{
NameLabel10.text = temp.PlayerName;
HighScoreLabel10.text = temp.Score.ToString();
}
else if (i == 10)
{
NameLabel11.text = temp.PlayerName;
HighScoreLabel11.text = temp.Score.ToString();
}
else if (i == 11)
{
NameLabel12.text = temp.PlayerName;
HighScoreLabel12.text = temp.Score.ToString();
}
else if (i == 12)
{
NameLabel13.text = temp.PlayerName;
HighScoreLabel13.text = temp.Score.ToString();
}
else if (i == 13)
{
NameLabel14.text = temp.PlayerName;
HighScoreLabel14.text = temp.Score.ToString();
}
else if (i == 14)
{
NameLabel15.text = temp.PlayerName;
HighScoreLabel15.text = temp.Score.ToString();
}
else if (i == 15)
{
NameLabel16.text = temp.PlayerName;
HighScoreLabel16.text = temp.Score.ToString();
}
else if (i == 16)
{
NameLabel17.text = temp.PlayerName;
HighScoreLabel17.text = temp.Score.ToString();
}
else if (i == 17)
{
NameLabel18.text = temp.PlayerName;
HighScoreLabel18.text = temp.Score.ToString();
}
else if (i == 18)
{
NameLabel19.text = temp.PlayerName;
HighScoreLabel19.text = temp.Score.ToString();
}
else if (i == 19)
{
NameLabel20.text = temp.PlayerName;
HighScoreLabel20.text = temp.Score.ToString();
}

indexOfName += NextindexOffset;
indexOfScore += NextindexOffset;
}
}

public void SetUserProfileArray(string[] aRes)
{
UserProfileArray = aRes;
}

public void OnButtonClickAllTimeFriends()
{
ShowGlobalLeaderBoard();
}
}

Leave a Reply