93 lines
3.2 KiB
C#
93 lines
3.2 KiB
C#
|
|
using System.Collections.Generic;
|
|||
|
|
using TMPro;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.SceneManagement;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
|
|||
|
|
public class Leaderboard : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
[Header("━━━ UI SLOTS (10 satır) ━━━━━━━━━━━━━━━")]
|
|||
|
|
public TMP_Text[] rows;
|
|||
|
|
|
|||
|
|
[Header("━━━ BUTONLAR ━━━━━━━━━━━━━━━━━━━━━━━━━━")]
|
|||
|
|
public Button mainMenuButton;
|
|||
|
|
|
|||
|
|
[Header("━━━ MOD SKOR KEYLERİ ━━━━━━━━━━━━━━━━━━")]
|
|||
|
|
public string[] modScoreKeys; // Inspector'dan 12 key gir
|
|||
|
|
|
|||
|
|
// ─── Sabitler ────────────────────────────────
|
|||
|
|
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>();
|
|||
|
|
|
|||
|
|
// ─── Bot skorları ─────────────────────────
|
|||
|
|
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)));
|
|||
|
|
|
|||
|
|
// ─── Tüm modların toplamı ─────────────────
|
|||
|
|
int totalScore = 0;
|
|||
|
|
if (modScoreKeys != null)
|
|||
|
|
{
|
|||
|
|
foreach (string key in modScoreKeys)
|
|||
|
|
{
|
|||
|
|
if (!string.IsNullOrEmpty(key))
|
|||
|
|
totalScore += PlayerPrefs.GetInt(key + "_High", 0);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ─── Yüksek skor güncelle ─────────────────
|
|||
|
|
int savedTotal = PlayerPrefs.GetInt("TotalHighScore", 0);
|
|||
|
|
if (totalScore > savedTotal)
|
|||
|
|
{
|
|||
|
|
savedTotal = totalScore;
|
|||
|
|
PlayerPrefs.SetInt("TotalHighScore", savedTotal);
|
|||
|
|
PlayerPrefs.Save();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
list.Add(new LBEntry("YOU", savedTotal));
|
|||
|
|
|
|||
|
|
// ─── Sırala ───────────────────────────────
|
|||
|
|
list.Sort((a, b) => b.score.CompareTo(a.score));
|
|||
|
|
|
|||
|
|
// ─── Ekrana yaz ───────────────────────────
|
|||
|
|
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}. ---";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|