完成编队 增加多个细节和小功能

This commit is contained in:
FloatGaming
2025-12-10 19:12:27 +08:00
parent c0a822b958
commit edc2608f47
131 changed files with 11889 additions and 127 deletions
+110
View File
@@ -5,12 +5,21 @@ using System.Collections;
public class newTeamSelector : MonoBehaviour
{
public static newTeamSelector Instance { get; private set; }
[Header("等级图片CBAS")]
public Sprite levelIcon_sprite_C;
public Sprite levelIcon_sprite_B;
public Sprite levelIcon_sprite_A;
public Sprite levelIcon_sprite_S;
[Header("已选择的队伍")]
public int selected_heroSlot01_heroID;
public int selected_heroSlot02_heroID;
public int selected_heroSlot03_heroID;
public int selected_heroSlot04_heroID;
public int selected_heroSlot05_heroID;
[Tooltip("Prefab for a single hero slot. Must contain slots_heroSlots component.")]
public GameObject slotPrefab;
@@ -28,10 +37,23 @@ public class newTeamSelector : MonoBehaviour
private readonly List<slots_heroSlots> createdSlots = new List<slots_heroSlots>();
void Awake()
{
if (Instance == null)
{
Instance = this;
}
else
{
Destroy(gameObject);
}
}
void Start()
{
if (instantiateOnStart)
CreateSlots();
LoadSelectedHeroes();
}
void Update() { }
@@ -137,4 +159,92 @@ public class newTeamSelector : MonoBehaviour
}
public List<slots_heroSlots> GetCreatedSlots() => createdSlots;
public void UpdateAndSaveSelectedHeroes()
{
if (createdSlots.Count > 0) selected_heroSlot01_heroID = createdSlots[0].heroSlot_heroID;
if (createdSlots.Count > 1) selected_heroSlot02_heroID = createdSlots[1].heroSlot_heroID;
if (createdSlots.Count > 2) selected_heroSlot03_heroID = createdSlots[2].heroSlot_heroID;
if (createdSlots.Count > 3) selected_heroSlot04_heroID = createdSlots[3].heroSlot_heroID;
if (createdSlots.Count > 4) selected_heroSlot05_heroID = createdSlots[4].heroSlot_heroID;
PlayerPrefs.SetInt("selected_heroSlot01_heroID", selected_heroSlot01_heroID);
PlayerPrefs.SetInt("selected_heroSlot02_heroID", selected_heroSlot02_heroID);
PlayerPrefs.SetInt("selected_heroSlot03_heroID", selected_heroSlot03_heroID);
PlayerPrefs.SetInt("selected_heroSlot04_heroID", selected_heroSlot04_heroID);
PlayerPrefs.SetInt("selected_heroSlot05_heroID", selected_heroSlot05_heroID);
PlayerPrefs.Save();
Debug.Log("已保存当前队伍到PlayerPrefs");
}
public void LoadSelectedHeroes()
{
if (createdSlots.Count == 0) return;
selected_heroSlot01_heroID = PlayerPrefs.GetInt("selected_heroSlot01_heroID", 0);
selected_heroSlot02_heroID = PlayerPrefs.GetInt("selected_heroSlot02_heroID", 0);
selected_heroSlot03_heroID = PlayerPrefs.GetInt("selected_heroSlot03_heroID", 0);
selected_heroSlot04_heroID = PlayerPrefs.GetInt("selected_heroSlot04_heroID", 0);
selected_heroSlot05_heroID = PlayerPrefs.GetInt("selected_heroSlot05_heroID", 0);
// Set the slots
if (createdSlots.Count > 0) createdSlots[0].heroSlot_heroID = selected_heroSlot01_heroID;
if (createdSlots.Count > 1) createdSlots[1].heroSlot_heroID = selected_heroSlot02_heroID;
if (createdSlots.Count > 2) createdSlots[2].heroSlot_heroID = selected_heroSlot03_heroID;
if (createdSlots.Count > 3) createdSlots[3].heroSlot_heroID = selected_heroSlot04_heroID;
if (createdSlots.Count > 4) createdSlots[4].heroSlot_heroID = selected_heroSlot05_heroID;
// Update each slot's UI
for (int i = 0; i < createdSlots.Count; i++)
{
var slot = createdSlots[i];
if (slot.heroSlot_heroID != 0)
{
// Find the hero SO
AllyHero_SO hero = FindHeroById(slot.heroSlot_heroID);
if (hero != null)
{
slot.SetSlot(slot.heroSlot_heroID, hero.ally_heroName, hero.ally_heroPoster);
}
}
else
{
// Clear slot logic
slot.heroSlot_heroID = 0;
if (slot.heroSlot_heroName != null) slot.heroSlot_heroName.text = "空置";
if (slot.heroImage != null)
{
// revert to default sprite if provided, otherwise keep transparent
if (slot.defaultHeroSprite != null)
{
slot.heroImage.sprite = slot.defaultHeroSprite;
slot.heroImage.color = new Color(slot.heroImage.color.r, slot.heroImage.color.g, slot.heroImage.color.b, 1f);
}
else
{
slot.heroImage.sprite = null;
slot.heroImage.color = new Color(slot.heroImage.color.r, slot.heroImage.color.g, slot.heroImage.color.b, 0f);
}
}
if (slot.heroLevelImage != null)
{
slot.heroLevelImage.sprite = null;
slot.heroLevelImage.color = new Color(1f, 1f, 1f, 0f);
}
// Update skill list
slot.UpdateSkillList();
}
}
}
private AllyHero_SO FindHeroById(int id)
{
var arr = Resources.LoadAll<AllyHero_SO>("");
foreach (var a in arr)
{
if (a != null && a.ally_heroID == id) return a;
}
return null;
}
}