修了不少东西
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
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";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user