修了不少东西

This commit is contained in:
FloatGaming
2026-07-16 23:04:59 +08:00
parent 29972d0705
commit 73fe474cc6
134 changed files with 7673 additions and 741 deletions
@@ -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";
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 7dfd23d5af82d6045b465356990ca8b9
@@ -147,21 +147,21 @@ public class TeamSelectorAnimController : MonoBehaviour
void CacheTeamSnapshot()
{
cachedTeam[0] = PlayerPrefs.GetInt("selected_heroSlot01_heroID", 0);
cachedTeam[1] = PlayerPrefs.GetInt("selected_heroSlot02_heroID", 0);
cachedTeam[2] = PlayerPrefs.GetInt("selected_heroSlot03_heroID", 0);
cachedTeam[3] = PlayerPrefs.GetInt("selected_heroSlot04_heroID", 0);
cachedTeam[4] = PlayerPrefs.GetInt("selected_heroSlot05_heroID", 0);
cachedTeam[0] = TeamSelectionDefaults.ReadHeroId(1);
cachedTeam[1] = TeamSelectionDefaults.ReadHeroId(2);
cachedTeam[2] = TeamSelectionDefaults.ReadHeroId(3);
cachedTeam[3] = TeamSelectionDefaults.ReadHeroId(4);
cachedTeam[4] = TeamSelectionDefaults.ReadHeroId(5);
}
bool HasTeamChanged()
{
if (teamChanged) return true;
if (cachedTeam[0] != PlayerPrefs.GetInt("selected_heroSlot01_heroID", 0)) return true;
if (cachedTeam[1] != PlayerPrefs.GetInt("selected_heroSlot02_heroID", 0)) return true;
if (cachedTeam[2] != PlayerPrefs.GetInt("selected_heroSlot03_heroID", 0)) return true;
if (cachedTeam[3] != PlayerPrefs.GetInt("selected_heroSlot04_heroID", 0)) return true;
if (cachedTeam[4] != PlayerPrefs.GetInt("selected_heroSlot05_heroID", 0)) return true;
if (cachedTeam[0] != TeamSelectionDefaults.ReadHeroId(1)) return true;
if (cachedTeam[1] != TeamSelectionDefaults.ReadHeroId(2)) return true;
if (cachedTeam[2] != TeamSelectionDefaults.ReadHeroId(3)) return true;
if (cachedTeam[3] != TeamSelectionDefaults.ReadHeroId(4)) return true;
if (cachedTeam[4] != TeamSelectionDefaults.ReadHeroId(5)) return true;
return false;
}
+6 -5
View File
@@ -289,12 +289,13 @@ public class newTeamSelector : MonoBehaviour
private int[] ReadSelectedHeroIdsFromPlayerPrefs()
{
TeamSelectionDefaults.EnsureDefaultTeamIfMissing();
int[] ids = new int[Mathf.Max(5, slotCount)];
if (ids.Length > 0) ids[0] = Mathf.Max(0, PlayerPrefs.GetInt("selected_heroSlot01_heroID", 0));
if (ids.Length > 1) ids[1] = Mathf.Max(0, PlayerPrefs.GetInt("selected_heroSlot02_heroID", 0));
if (ids.Length > 2) ids[2] = Mathf.Max(0, PlayerPrefs.GetInt("selected_heroSlot03_heroID", 0));
if (ids.Length > 3) ids[3] = Mathf.Max(0, PlayerPrefs.GetInt("selected_heroSlot04_heroID", 0));
if (ids.Length > 4) ids[4] = Mathf.Max(0, PlayerPrefs.GetInt("selected_heroSlot05_heroID", 0));
if (ids.Length > 0) ids[0] = TeamSelectionDefaults.ReadHeroId(1);
if (ids.Length > 1) ids[1] = TeamSelectionDefaults.ReadHeroId(2);
if (ids.Length > 2) ids[2] = TeamSelectionDefaults.ReadHeroId(3);
if (ids.Length > 3) ids[3] = TeamSelectionDefaults.ReadHeroId(4);
if (ids.Length > 4) ids[4] = TeamSelectionDefaults.ReadHeroId(5);
return ids;
}