技能主要更新,修复卡顿并加入动画,以及各种其他更新。
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class load_teammatesProfile : MonoBehaviour
|
||||
{
|
||||
private static Dictionary<int, AllyHero_SO> heroById;
|
||||
private static bool heroCacheReady;
|
||||
private static bool heroCacheBuilding;
|
||||
|
||||
[Header("½ÇɫͷÏñ")]
|
||||
public Image teammate_profile_01;
|
||||
public Image teammate_profile_02;
|
||||
@@ -25,13 +30,60 @@ public class load_teammatesProfile : MonoBehaviour
|
||||
public Color levelColor_S;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
IEnumerator Start()
|
||||
{
|
||||
yield return EnsureHeroCache();
|
||||
update_teammates_profile();
|
||||
}
|
||||
|
||||
private IEnumerator EnsureHeroCache()
|
||||
{
|
||||
if (heroCacheReady) yield break;
|
||||
if (heroCacheBuilding)
|
||||
{
|
||||
while (!heroCacheReady)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
yield break;
|
||||
}
|
||||
|
||||
heroCacheBuilding = true;
|
||||
var allHeroes = Resources.LoadAll<AllyHero_SO>("");
|
||||
heroById = new Dictionary<int, AllyHero_SO>();
|
||||
if (allHeroes != null)
|
||||
{
|
||||
for (int i = 0; i < allHeroes.Length; i++)
|
||||
{
|
||||
var hero = allHeroes[i];
|
||||
if (hero != null && !heroById.ContainsKey(hero.ally_heroID))
|
||||
{
|
||||
heroById.Add(hero.ally_heroID, hero);
|
||||
}
|
||||
if ((i % 32) == 0)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
heroCacheReady = true;
|
||||
heroCacheBuilding = false;
|
||||
}
|
||||
|
||||
private IEnumerator EnsureHeroCacheThenUpdate()
|
||||
{
|
||||
yield return EnsureHeroCache();
|
||||
update_teammates_profile();
|
||||
}
|
||||
|
||||
public void update_teammates_profile()
|
||||
{
|
||||
if (!heroCacheReady)
|
||||
{
|
||||
StartCoroutine(EnsureHeroCacheThenUpdate());
|
||||
return;
|
||||
}
|
||||
// Load selected hero IDs from PlayerPrefs
|
||||
int heroId1 = PlayerPrefs.GetInt("selected_heroSlot01_heroID", 0);
|
||||
int heroId2 = PlayerPrefs.GetInt("selected_heroSlot02_heroID", 0);
|
||||
@@ -56,36 +108,21 @@ public class load_teammatesProfile : MonoBehaviour
|
||||
|
||||
private Sprite GetHeroSquareProfile(int heroId)
|
||||
{
|
||||
if (heroId == 0) return null;
|
||||
|
||||
// Load all AllyHero_SO and find the one with matching ID
|
||||
var allHeroes = Resources.LoadAll<AllyHero_SO>("");
|
||||
foreach (var hero in allHeroes)
|
||||
if (heroId == 0 || heroById == null) return null;
|
||||
AllyHero_SO hero;
|
||||
if (heroById.TryGetValue(heroId, out hero) && hero != null)
|
||||
{
|
||||
if (hero != null && hero.ally_heroID == heroId)
|
||||
{
|
||||
return hero.ally_hero_squareProfile;
|
||||
}
|
||||
return hero.ally_hero_squareProfile;
|
||||
}
|
||||
return null; // Not found
|
||||
return null;
|
||||
}
|
||||
|
||||
private string GetHeroLevel(int heroId)
|
||||
{
|
||||
if (heroId == 0) return "C"; // default
|
||||
|
||||
var allHeroes = Resources.LoadAll<AllyHero_SO>("");
|
||||
AllyHero_SO hero = null;
|
||||
foreach (var h in allHeroes)
|
||||
{
|
||||
if (h != null && h.ally_heroID == heroId)
|
||||
{
|
||||
hero = h;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hero == null) return "C";
|
||||
|
||||
if (heroId == 0) return "C";
|
||||
if (heroById == null) return "C";
|
||||
AllyHero_SO hero;
|
||||
if (!heroById.TryGetValue(heroId, out hero) || hero == null) return "C";
|
||||
return GetRatingFromSO(hero);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user