一些修复和优化

This commit is contained in:
FloatGaming
2026-07-20 02:22:51 +08:00
parent 818fc9a02f
commit 0a0872c4f4
49 changed files with 2008 additions and 262 deletions
+70 -70
View File
@@ -91,9 +91,11 @@ public class UI_Idols : MonoBehaviour
private int pendingGrowthAnimationHeroId = -1;
private Tween idolExpBarTween;
private Coroutine startupSkillValidationRoutine;
private bool hasStarted;
private void Start()
{
hasStarted = true;
BindQuitButton();
InitializeSectionToggles();
RebuildCards();
@@ -108,7 +110,10 @@ public class UI_Idols : MonoBehaviour
AllyHeroDeployLedger.EnsureInstance().OnHeroGrowthChanged += HandleHeroGrowthChanged;
StoreOwnershipLedger.EnsureInstance().OnOwnershipChanged += HandleOwnershipChanged;
InitializeSectionToggles();
RebuildCards();
if (hasStarted)
{
RebuildCards();
}
HandleOverlayPanelsVisibilityChanged(btmandtopController.CurrentOverlayPanelsVisible);
}
@@ -399,6 +404,7 @@ public class UI_Idols : MonoBehaviour
AllyHero_SO firstDisplayedHero = null;
AllyHero_SO preferredHero = currentSelectedHero;
bool preferredHeroDisplayed = false;
int visibleCardCount = 0;
for (int i = 0; i < heroes.Count; i++)
{
@@ -414,8 +420,8 @@ public class UI_Idols : MonoBehaviour
}
IdolLevelSnapshot snapshot = BuildLevelSnapshot(hero);
GameObject instance = Instantiate(idolCardPrefab, idolCardParent);
spawnedCards.Add(instance);
GameObject instance = GetOrCreateCard(visibleCardCount);
visibleCardCount++;
idolCardPrefab card = instance.GetComponent<idolCardPrefab>();
if (card == null)
@@ -686,8 +692,7 @@ public class UI_Idols : MonoBehaviour
continue;
}
GameObject instance = Instantiate(ssPrefab, ssParent);
spawnedSpecialSkillEntries.Add(instance);
GameObject instance = GetOrCreateSpecialSkillEntry(shown);
ssPrefab display = instance.GetComponent<ssPrefab>();
if (display != null)
@@ -760,47 +765,15 @@ public class UI_Idols : MonoBehaviour
{
for (int i = spawnedCards.Count - 1; i >= 0; i--)
{
if (spawnedCards[i] == null)
GameObject card = spawnedCards[i];
if (card == null)
{
continue;
}
#if UNITY_EDITOR
if (!Application.isPlaying)
if (card.activeSelf)
{
DestroyImmediate(spawnedCards[i]);
}
else
#endif
{
Destroy(spawnedCards[i]);
}
}
spawnedCards.Clear();
if (idolCardParent == null)
{
return;
}
for (int i = idolCardParent.childCount - 1; i >= 0; i--)
{
Transform child = idolCardParent.GetChild(i);
if (child == null || child.GetComponent<idolCardPrefab>() == null)
{
continue;
}
#if UNITY_EDITOR
if (!Application.isPlaying)
{
DestroyImmediate(child.gameObject);
}
else
#endif
{
Destroy(child.gameObject);
card.SetActive(false);
}
}
}
@@ -809,49 +782,61 @@ public class UI_Idols : MonoBehaviour
{
for (int i = spawnedSpecialSkillEntries.Count - 1; i >= 0; i--)
{
if (spawnedSpecialSkillEntries[i] == null)
GameObject entry = spawnedSpecialSkillEntries[i];
if (entry == null)
{
continue;
}
#if UNITY_EDITOR
if (!Application.isPlaying)
if (entry.activeSelf)
{
DestroyImmediate(spawnedSpecialSkillEntries[i]);
}
else
#endif
{
Destroy(spawnedSpecialSkillEntries[i]);
entry.SetActive(false);
}
}
}
spawnedSpecialSkillEntries.Clear();
if (ssParent == null)
private GameObject GetOrCreateCard(int index)
{
while (spawnedCards.Count <= index)
{
return;
GameObject instance = Instantiate(idolCardPrefab, idolCardParent);
spawnedCards.Add(instance);
}
for (int i = ssParent.childCount - 1; i >= 0; i--)
GameObject card = spawnedCards[index];
if (card != null)
{
Transform child = ssParent.GetChild(i);
if (child == null || child.GetComponent<ssPrefab>() == null)
card.transform.SetParent(idolCardParent, false);
card.transform.SetSiblingIndex(index);
if (!card.activeSelf)
{
continue;
}
#if UNITY_EDITOR
if (!Application.isPlaying)
{
DestroyImmediate(child.gameObject);
}
else
#endif
{
Destroy(child.gameObject);
card.SetActive(true);
}
}
return card;
}
private GameObject GetOrCreateSpecialSkillEntry(int index)
{
while (spawnedSpecialSkillEntries.Count <= index)
{
GameObject instance = Instantiate(ssPrefab, ssParent);
spawnedSpecialSkillEntries.Add(instance);
}
GameObject entry = spawnedSpecialSkillEntries[index];
if (entry != null)
{
entry.transform.SetParent(ssParent, false);
entry.transform.SetSiblingIndex(index);
if (!entry.activeSelf)
{
entry.SetActive(true);
}
}
return entry;
}
private static void SetText(Text target, string value)
@@ -1023,7 +1008,22 @@ public class UI_Idols : MonoBehaviour
public void RefreshCurrentHeroDetails()
{
ApplyHeroDetails(currentSelectedHero, false);
if (currentSelectedHero == null)
{
ApplyHeroDetails(null, false);
return;
}
IdolLevelSnapshot snapshot = BuildLevelSnapshot(currentSelectedHero);
SetSliderVisual(idol_expBar, snapshot.sliderValue, snapshot.sliderColor, false);
SetText(idol_expText, snapshot.detailXpText);
SetImageSprite(levelIcon, snapshot.levelIcon);
ApplyLevelDetails(GetEffectiveLevelInfoFromLedger(currentSelectedHero));
if (ieqpmt != null)
{
ieqpmt.RefreshCurrentHeroEquipmentState();
}
}
private void ApplyBehaviourRadar(AllyHero_SO hero)
+102 -33
View File
@@ -73,6 +73,10 @@ public class idolEquipments : MonoBehaviour
private float pendingScrollbarValue = 1f;
private Coroutine restoreScrollbarRoutine;
private bool suppressDropdownCallbacks;
private bool hasStarted;
private bool equipmentOwnershipCacheReady;
private readonly Dictionary<equipmentSO, AllyHero_SO> ownershipByReference = new Dictionary<equipmentSO, AllyHero_SO>();
private readonly Dictionary<string, AllyHero_SO> ownershipByName = new Dictionary<string, AllyHero_SO>(StringComparer.Ordinal);
private static readonly (EquipFilterMode mode, string label)[] FilterOptions =
{
@@ -102,6 +106,7 @@ public class idolEquipments : MonoBehaviour
private void Start()
{
hasStarted = true;
InitializeDropdowns();
InitializeOnlyCanEquipToggle();
BindControls();
@@ -116,8 +121,11 @@ public class idolEquipments : MonoBehaviour
InitializeOnlyCanEquipToggle();
BindControls();
RestoreEquippedFromHero();
RebuildBag();
RefreshEquippedSlot();
if (hasStarted)
{
RebuildBag();
RefreshEquippedSlot();
}
}
private void OnDisable()
@@ -267,6 +275,8 @@ public class idolEquipments : MonoBehaviour
return;
}
RefreshEquipmentOwnershipCache();
List<equipmentSO> equipments = LoadEquipments()
.Where(e => e != null)
.Where(e => !equipSmelt.IsEquipmentAssignedToSmeltPool(e) && !equipSmelt.ShouldHideConsumedEquipment(e))
@@ -292,7 +302,7 @@ public class idolEquipments : MonoBehaviour
int batchSize = Mathf.Max(1, i_batch);
for (int i = 0; i < equipments.Count; i++)
{
SpawnBagItem(equipments[i]);
SpawnBagItem(equipments[i], i);
if ((i + 1) % batchSize == 0)
{
yield return null;
@@ -307,18 +317,18 @@ public class idolEquipments : MonoBehaviour
{
for (int i = 0; i < equipments.Count; i++)
{
SpawnBagItem(equipments[i]);
SpawnBagItem(equipments[i], i);
}
}
private void SpawnBagItem(equipmentSO equipment)
private void SpawnBagItem(equipmentSO equipment, int index)
{
if (equipment == null || eqpmtItemPrefab == null || eqpmtBagParent == null)
{
return;
}
GameObject instance = Instantiate(eqpmtItemPrefab, eqpmtBagParent);
GameObject instance = GetOrCreateBagItem(index);
instance.name = string.IsNullOrWhiteSpace(equipment.GetDisplayTierName()) ? equipment.name : equipment.GetDisplayTierName();
equipItemPrefab item = instance.GetComponent<equipItemPrefab>();
@@ -332,8 +342,6 @@ public class idolEquipments : MonoBehaviour
item.itemButton.interactable = true;
}
}
spawnedBagItems.Add(instance);
}
private bool HandleBagItemRightClicked(equipmentSO equipment)
@@ -372,7 +380,8 @@ public class idolEquipments : MonoBehaviour
{
currentHero.SetEquippedEquipment(equipment);
}
RefreshAllIdolPanels();
equipmentOwnershipCacheReady = false;
RefreshAllIdolPanels(GetComponentInParent<UI_Idols>(true));
RefreshEquippedSlot();
RebuildBag();
}
@@ -384,7 +393,8 @@ public class idolEquipments : MonoBehaviour
{
currentHero.ClearEquippedEquipment();
}
RefreshAllIdolPanels();
equipmentOwnershipCacheReady = false;
RefreshAllIdolPanels(GetComponentInParent<UI_Idols>(true));
RefreshEquippedSlot();
RebuildBag();
}
@@ -392,6 +402,15 @@ public class idolEquipments : MonoBehaviour
public void SetHero(AllyHero_SO hero)
{
currentHero = hero;
equipmentOwnershipCacheReady = false;
RestoreEquippedFromHero();
RefreshEquippedSlot();
RebuildBag();
}
public void RefreshCurrentHeroEquipmentState()
{
equipmentOwnershipCacheReady = false;
RestoreEquippedFromHero();
RefreshEquippedSlot();
RebuildBag();
@@ -493,22 +512,21 @@ public class idolEquipments : MonoBehaviour
return false;
}
AllyHero_SO[] heroes = LoadHeroAssetsForOwnershipCheck();
for (int i = 0; i < heroes.Length; i++)
if (!equipmentOwnershipCacheReady)
{
AllyHero_SO hero = heroes[i];
if (hero == null || hero == currentHero)
{
continue;
}
RefreshEquipmentOwnershipCache();
}
hero.LoadEquippedEquipmentFromLocal();
equipmentSO equipped = hero.GetEquippedEquipmentResolved();
if (equipped == equipment || (!string.IsNullOrWhiteSpace(equipped?.name) && equipped.name == equipment.name))
{
occupiedHero = hero;
return true;
}
if (ownershipByReference.TryGetValue(equipment, out occupiedHero) && occupiedHero != null)
{
return true;
}
if (!string.IsNullOrWhiteSpace(equipment.name) &&
ownershipByName.TryGetValue(equipment.name, out occupiedHero) &&
occupiedHero != null)
{
return true;
}
return false;
@@ -567,13 +585,13 @@ public class idolEquipments : MonoBehaviour
}
}
private void RefreshAllIdolPanels()
private void RefreshAllIdolPanels(UI_Idols skipPanel = null)
{
UI_Idols[] panels = FindObjectsByType<UI_Idols>(FindObjectsInactive.Include, FindObjectsSortMode.None);
for (int i = 0; i < panels.Length; i++)
{
UI_Idols panel = panels[i];
if (panel != null)
if (panel != null && panel != skipPanel)
{
panel.RefreshCurrentHeroDetails();
}
@@ -582,16 +600,14 @@ public class idolEquipments : MonoBehaviour
private void ClearBagItems()
{
for (int i = eqpmtBagParent != null ? eqpmtBagParent.childCount - 1 : -1; i >= 0; i--)
for (int i = spawnedBagItems.Count - 1; i >= 0; i--)
{
Transform child = eqpmtBagParent.GetChild(i);
if (child != null)
GameObject item = spawnedBagItems[i];
if (item != null && item.activeSelf)
{
Destroy(child.gameObject);
item.SetActive(false);
}
}
spawnedBagItems.Clear();
}
private void CacheScrollbarValue()
@@ -765,7 +781,7 @@ public class idolEquipments : MonoBehaviour
else
#endif
{
results.AddRange(Resources.LoadAll<equipmentSO>(runtimeEquipmentFolder).Where(e => e != null));
results.AddRange(RuntimeResourcesCache.LoadAll<equipmentSO>(runtimeEquipmentFolder).Where(e => e != null));
}
for (int i = 0; i < results.Count; i++)
@@ -903,4 +919,57 @@ public class idolEquipments : MonoBehaviour
string raw = equipment.name.Replace("(Clone)", string.Empty).Replace("(Preview)", string.Empty).Replace("(TourPreview)", string.Empty);
return raw.StartsWith("type", StringComparison.OrdinalIgnoreCase) && raw.Length > 4 ? raw.Substring(4) : raw;
}
private GameObject GetOrCreateBagItem(int index)
{
while (spawnedBagItems.Count <= index)
{
GameObject instance = Instantiate(eqpmtItemPrefab, eqpmtBagParent);
spawnedBagItems.Add(instance);
}
GameObject item = spawnedBagItems[index];
if (item != null)
{
item.transform.SetParent(eqpmtBagParent, false);
item.transform.SetSiblingIndex(index);
if (!item.activeSelf)
{
item.SetActive(true);
}
}
return item;
}
private void RefreshEquipmentOwnershipCache()
{
ownershipByReference.Clear();
ownershipByName.Clear();
AllyHero_SO[] heroes = LoadHeroAssetsForOwnershipCheck();
for (int i = 0; i < heroes.Length; i++)
{
AllyHero_SO hero = heroes[i];
if (hero == null || hero == currentHero)
{
continue;
}
hero.LoadEquippedEquipmentFromLocal();
equipmentSO equipped = hero.GetEquippedEquipmentResolved();
if (equipped == null)
{
continue;
}
ownershipByReference[equipped] = hero;
if (!string.IsNullOrWhiteSpace(equipped.name))
{
ownershipByName[equipped.name] = hero;
}
}
equipmentOwnershipCacheReady = true;
}
}
+33 -20
View File
@@ -30,6 +30,7 @@ public class idolSkillsHub : MonoBehaviour
[Header("runtime")]
public AllyHero_SO currentHero;
private int selectedDetailSkillGroupId = -1;
private readonly List<GameObject> spawnedSkillItems = new List<GameObject>();
public void SetHero(AllyHero_SO hero)
{
@@ -61,6 +62,8 @@ public class idolSkillsHub : MonoBehaviour
int currentTierNumber = GetCurrentTierNumber(currentHero);
int maxSkillSlots = currentHero.GetEffectiveSkillSlotLimit();
int equippedCount = GetEquippedCount();
int visibleIndex = 0;
for (int i = 0; i < currentHero.skillGroups.Length; i++)
{
@@ -72,7 +75,7 @@ public class idolSkillsHub : MonoBehaviour
bool unlocked = currentTierNumber >= Mathf.Clamp(group.thisSkill_levelLimit, 1, 4);
bool equipped = IsEquipped(group.skillGroupID);
bool slotAvailable = equipped || GetEquippedCount() < maxSkillSlots;
bool slotAvailable = equipped || equippedCount < maxSkillSlots;
string enableText;
bool enableToggleValue;
@@ -106,7 +109,8 @@ public class idolSkillsHub : MonoBehaviour
Color bottomColor = equipped ? enabled_btmColor : (unlocked ? disabled_btmColor : unlock_btmColor);
Material iconMaterial = unlocked ? null : disgot_grayMtr;
GameObject instance = Instantiate(deSkillPrefab, deSkillContainer);
GameObject instance = GetOrCreateSkillItem(visibleIndex);
visibleIndex++;
deSkillPrefab item = instance.GetComponent<deSkillPrefab>();
if (item == null)
{
@@ -286,31 +290,40 @@ public class idolSkillsHub : MonoBehaviour
private void ClearItems()
{
if (deSkillContainer == null)
for (int i = spawnedSkillItems.Count - 1; i >= 0; i--)
{
return;
}
for (int i = deSkillContainer.childCount - 1; i >= 0; i--)
{
Transform child = deSkillContainer.GetChild(i);
if (child == null)
GameObject item = spawnedSkillItems[i];
if (item == null)
{
continue;
}
#if UNITY_EDITOR
if (!Application.isPlaying)
if (item.activeSelf)
{
DestroyImmediate(child.gameObject);
item.SetActive(false);
}
else
{
Destroy(child.gameObject);
}
#else
Destroy(child.gameObject);
#endif
}
}
private GameObject GetOrCreateSkillItem(int index)
{
while (spawnedSkillItems.Count <= index)
{
GameObject instance = Instantiate(deSkillPrefab, deSkillContainer);
spawnedSkillItems.Add(instance);
}
GameObject item = spawnedSkillItems[index];
if (item != null)
{
item.transform.SetParent(deSkillContainer, false);
item.transform.SetSiblingIndex(index);
if (!item.activeSelf)
{
item.SetActive(true);
}
}
return item;
}
}