71 lines
2.6 KiB
C#
71 lines
2.6 KiB
C#
|
|
using System.Collections.Generic;
|
|||
|
|
using TMPro;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.SceneManagement;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
public class ModLeaderboard : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
[Header("━━━ UI SLOTS (10 satır) ━━━━━━━━━━━━━━━")]
|
|||
|
|
public TMP_Text[] rows;
|
|||
|
|
[Header("━━━ BUTONLAR ━━━━━━━━━━━━━━━━━━━━━━━━━━")]
|
|||
|
|
public Button mainMenuButton;
|
|||
|
|
[Header("━━━ MOD AYARI ━━━━━━━━━━━━━━━━━━━━━━━━━")]
|
|||
|
|
public string scoreKey = "GalaxyScore";
|
|||
|
|
//
|
|||
|
|
// Her mod için scoreKey değeri:
|
|||
|
|
// ─────────────────────────────
|
|||
|
|
// Galaxy Modu → "GalaxyScore"
|
|||
|
|
// Time Modu → "TimeScore"
|
|||
|
|
// Classic Modu → "ClassicScore"
|
|||
|
|
// Challenge Modu → "ChallengeScore"
|
|||
|
|
private readonly string[] botNames =
|
|||
|
|
{
|
|||
|
|
"ShadowWolf", "CrystalMind", "NightHunter",
|
|||
|
|
"BlueVortex", "IronSoul", "PixelGhost",
|
|||
|
|
"SilverClaw", "MegaCore", "NeonBlade", "DarkNova"
|
|||
|
|
};
|
|||
|
|
class LBEntry
|
|||
|
|
{
|
|||
|
|
public string name;
|
|||
|
|
public int score;
|
|||
|
|
public LBEntry(string n, int s) { name = n; score = s; }
|
|||
|
|
}
|
|||
|
|
void Start()
|
|||
|
|
{
|
|||
|
|
GenerateLeaderboard();
|
|||
|
|
if (mainMenuButton != null)
|
|||
|
|
mainMenuButton.onClick.AddListener(() =>
|
|||
|
|
SceneManager.LoadScene("Anamen"));
|
|||
|
|
}
|
|||
|
|
void GenerateLeaderboard()
|
|||
|
|
{
|
|||
|
|
List<LBEntry> list = new List<LBEntry>();
|
|||
|
|
int botLimit = Mathf.Min(rows.Length - 1, botNames.Length);
|
|||
|
|
for (int i = 0; i < botLimit; i++)
|
|||
|
|
list.Add(new LBEntry(botNames[i], Random.Range(3000, 12000)));
|
|||
|
|
string highKey = scoreKey + "_High";
|
|||
|
|
int lastScore = PlayerPrefs.GetInt(scoreKey, 0);
|
|||
|
|
int highScore = PlayerPrefs.GetInt(highKey, 0);
|
|||
|
|
if (lastScore > highScore)
|
|||
|
|
{
|
|||
|
|
highScore = lastScore;
|
|||
|
|
PlayerPrefs.SetInt(highKey, highScore);
|
|||
|
|
PlayerPrefs.Save();
|
|||
|
|
}
|
|||
|
|
list.Add(new LBEntry("YOU", highScore));
|
|||
|
|
list.Sort((a, b) => b.score.CompareTo(a.score));
|
|||
|
|
for (int i = 0; i < rows.Length; i++)
|
|||
|
|
{
|
|||
|
|
if (i < list.Count)
|
|||
|
|
{
|
|||
|
|
rows[i].text = list[i].name == "YOU"
|
|||
|
|
? $"<color=#00FF00>{i + 1}. {list[i].name} - {list[i].score}</color>"
|
|||
|
|
: $"{i + 1}. {list[i].name} - {list[i].score}";
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
rows[i].text = $"{i + 1}. ---";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|