一些修复和优化

This commit is contained in:
2026-07-20 02:22:51 +08:00
parent 818fc9a02f
commit 0a0872c4f4
49 changed files with 2008 additions and 262 deletions
+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;
}
}