Files
bansonic_beta_main/Assets/scripts/Team/TeamSelectionDefaults.cs
2026-07-16 23:04:59 +08:00

52 lines
1.4 KiB
C#

using UnityEngine;
public static class TeamSelectionDefaults
{
public const int SlotCount = 5;
private static readonly int[] DefaultHeroIds = { 30201, 30202, 30203, 30204, 30205 };
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
private static void Bootstrap()
{
EnsureDefaultTeamIfMissing();
}
public static void EnsureDefaultTeamIfMissing()
{
for (int slot = 1; slot <= SlotCount; slot++)
{
if (PlayerPrefs.HasKey(GetHeroSlotKey(slot)))
{
return;
}
}
for (int slot = 1; slot <= SlotCount; slot++)
{
PlayerPrefs.SetInt(GetHeroSlotKey(slot), GetDefaultHeroId(slot));
}
PlayerPrefs.SetInt("SelectedMainHeroID", DefaultHeroIds[0]);
PlayerPrefs.Save();
}
public static int ReadHeroId(int slot)
{
EnsureDefaultTeamIfMissing();
return Mathf.Max(0, PlayerPrefs.GetInt(GetHeroSlotKey(slot), GetDefaultHeroId(slot)));
}
public static int GetDefaultHeroId(int slot)
{
int index = Mathf.Clamp(slot - 1, 0, DefaultHeroIds.Length - 1);
return DefaultHeroIds[index];
}
private static string GetHeroSlotKey(int slot)
{
int safeSlot = Mathf.Clamp(slot, 1, SlotCount);
return $"selected_heroSlot0{safeSlot}_heroID";
}
}