更新ui
This commit is contained in:
@@ -89,6 +89,7 @@ public class AllyCombatant : MonoBehaviour, ICombatant
|
||||
private Image manaImage;
|
||||
private Image fadeManaImage;
|
||||
private TextMeshProUGUI nameText;
|
||||
private Text legacyNameText;
|
||||
public string allyName => nameText != null ? nameText.text : name;
|
||||
private TextMeshProUGUI healthRateText;
|
||||
private TextMeshProUGUI currentScoreText;
|
||||
@@ -287,18 +288,21 @@ public class AllyCombatant : MonoBehaviour, ICombatant
|
||||
|
||||
private IEnumerator InitialTriggerCheckCoroutine()
|
||||
{
|
||||
// Wait for singletons to be ready
|
||||
while (SkillBuilder.Instance == null || teamUIController.Instance == null)
|
||||
// Refresh identity/stats as soon as the gameplay UI controller is ready.
|
||||
// Do not block this on SkillBuilder, otherwise early-starting slots can stay
|
||||
// on the empty placeholder state until much later.
|
||||
while (teamUIController.Instance == null)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// Wait until teamUIController has finished loading ally SOs if they are async
|
||||
// or just wait a couple of frames to be sure
|
||||
// Wait a couple of frames so teamUIController.Start() can finish loading slot ids/SOs.
|
||||
yield return null;
|
||||
yield return null;
|
||||
|
||||
// Re-run initialization to ensure we have the correct MaxHP and skills from the loaded team
|
||||
ResolveUIReferences();
|
||||
|
||||
// Re-run initialization to ensure we have the correct identity/stats from the loaded team.
|
||||
if (allowOverwriteFromSO)
|
||||
{
|
||||
InitializeStatsFromData();
|
||||
@@ -309,6 +313,11 @@ public class AllyCombatant : MonoBehaviour, ICombatant
|
||||
|
||||
iBudeffPrefabController.Instance?.RegisterBaseline(this);
|
||||
|
||||
while (SkillBuilder.Instance == null)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// Final wait to ensure SkillBuilder's internal mapping is ready
|
||||
while (SkillBuilder.Instance.GetAllyHeroSOBySlot(slotIndex) == null)
|
||||
{
|
||||
@@ -353,6 +362,7 @@ public class AllyCombatant : MonoBehaviour, ICombatant
|
||||
// Try singleton first, fallback to scene search (works in editor)
|
||||
var ui = teamUIController.Instance != null ? teamUIController.Instance : SceneObjectLookupCache.FindAny<teamUIController>();
|
||||
if (ui == null) return;
|
||||
GameObject parent = null;
|
||||
switch (slotIndex)
|
||||
{
|
||||
case 0:
|
||||
@@ -365,6 +375,7 @@ public class AllyCombatant : MonoBehaviour, ICombatant
|
||||
healthRateText = ui.teammate01_healthRate;
|
||||
currentScoreText = ui.teammate01_current_scoreText;
|
||||
hurtRedImage = ui.teammate01_hurtRedImage;
|
||||
parent = ui.objectFather_ally01;
|
||||
break;
|
||||
case 1:
|
||||
characterImage = ui.teammate02_characterImage;
|
||||
@@ -376,6 +387,7 @@ public class AllyCombatant : MonoBehaviour, ICombatant
|
||||
healthRateText = ui.teammate02_healthRate;
|
||||
currentScoreText = ui.teammate02_current_scoreText;
|
||||
hurtRedImage = ui.teammate02_hurtRedImage;
|
||||
parent = ui.objectFather_ally02;
|
||||
break;
|
||||
case 2:
|
||||
characterImage = ui.teammate03_characterImage;
|
||||
@@ -387,6 +399,7 @@ public class AllyCombatant : MonoBehaviour, ICombatant
|
||||
healthRateText = ui.teammate03_healthRate;
|
||||
currentScoreText = ui.teammate03_current_scoreText;
|
||||
hurtRedImage = ui.teammate03_hurtRedImage;
|
||||
parent = ui.objectFather_ally03;
|
||||
break;
|
||||
case 3:
|
||||
characterImage = ui.teammate04_characterImage;
|
||||
@@ -398,6 +411,7 @@ public class AllyCombatant : MonoBehaviour, ICombatant
|
||||
healthRateText = ui.teammate04_healthRate;
|
||||
currentScoreText = ui.teammate04_current_scoreText;
|
||||
hurtRedImage = ui.teammate04_hurtRedImage;
|
||||
parent = ui.objectFather_ally04;
|
||||
break;
|
||||
case 4:
|
||||
characterImage = ui.teammate05_characterImage;
|
||||
@@ -409,24 +423,27 @@ public class AllyCombatant : MonoBehaviour, ICombatant
|
||||
healthRateText = ui.teammate05_healthRate;
|
||||
currentScoreText = ui.teammate05_current_scoreText;
|
||||
hurtRedImage = ui.teammate05_hurtRedImage;
|
||||
parent = ui.objectFather_ally05;
|
||||
break;
|
||||
}
|
||||
|
||||
legacyNameText = ResolveLegacyNameText(parent);
|
||||
|
||||
// If the assigned TMP field is null, attempt to resolve from the UI parent's object (teamUIController keeps objectFather references)
|
||||
if (currentScoreText == null)
|
||||
{
|
||||
GameObject parent = null;
|
||||
GameObject scoreParent = null;
|
||||
switch (slotIndex)
|
||||
{
|
||||
case 0: parent = ui.objectFather_ally01; break;
|
||||
case 1: parent = ui.objectFather_ally02; break;
|
||||
case 2: parent = ui.objectFather_ally03; break;
|
||||
case 3: parent = ui.objectFather_ally04; break;
|
||||
case 4: parent = ui.objectFather_ally05; break;
|
||||
case 0: scoreParent = ui.objectFather_ally01; break;
|
||||
case 1: scoreParent = ui.objectFather_ally02; break;
|
||||
case 2: scoreParent = ui.objectFather_ally03; break;
|
||||
case 3: scoreParent = ui.objectFather_ally04; break;
|
||||
case 4: scoreParent = ui.objectFather_ally05; break;
|
||||
}
|
||||
if (parent != null)
|
||||
if (scoreParent != null)
|
||||
{
|
||||
var tmp = parent.GetComponentInChildren<TextMeshProUGUI>(true);
|
||||
var tmp = scoreParent.GetComponentInChildren<TextMeshProUGUI>(true);
|
||||
if (tmp != null)
|
||||
{
|
||||
currentScoreText = tmp;
|
||||
@@ -439,7 +456,7 @@ public class AllyCombatant : MonoBehaviour, ICombatant
|
||||
case 3: ui.teammate04_current_scoreText = tmp; break;
|
||||
case 4: ui.teammate05_current_scoreText = tmp; break;
|
||||
}
|
||||
LogVerbose($"[AllyCombatant] Resolved currentScoreText for slot {slotIndex+1} from parent {parent.name} -> {tmp.gameObject.name}");
|
||||
LogVerbose($"[AllyCombatant] Resolved currentScoreText for slot {slotIndex+1} from parent {scoreParent.name} -> {tmp.gameObject.name}");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -448,7 +465,7 @@ public class AllyCombatant : MonoBehaviour, ICombatant
|
||||
try
|
||||
{
|
||||
// Avoid grabbing gameplay HUD extras like "mana%" which must stay legacy and is not score text.
|
||||
var allLegacy = parent.GetComponentsInChildren<Text>(true);
|
||||
var allLegacy = scoreParent.GetComponentsInChildren<Text>(true);
|
||||
for (int k = 0; k < allLegacy.Length; k++)
|
||||
{
|
||||
var t = allLegacy[k];
|
||||
@@ -473,7 +490,7 @@ public class AllyCombatant : MonoBehaviour, ICombatant
|
||||
case 3: ui.teammate04_current_scoreText = created; break;
|
||||
case 4: ui.teammate05_current_scoreText = created; break;
|
||||
}
|
||||
Debug.LogWarning($"[AllyCombatant] Found legacy Text for slot {slotIndex+1} under {parent.name}. Added/used TMP component on {go.name} and copied text.");
|
||||
Debug.LogWarning($"[AllyCombatant] Found legacy Text for slot {slotIndex+1} under {scoreParent.name}. Added/used TMP component on {go.name} and copied text.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -482,6 +499,29 @@ public class AllyCombatant : MonoBehaviour, ICombatant
|
||||
ResolveHudExtras();
|
||||
}
|
||||
|
||||
private Text ResolveLegacyNameText(GameObject parent)
|
||||
{
|
||||
if (parent == null) return null;
|
||||
|
||||
var allLegacy = parent.GetComponentsInChildren<Text>(true);
|
||||
for (int i = 0; i < allLegacy.Length; i++)
|
||||
{
|
||||
var candidate = allLegacy[i];
|
||||
if (candidate == null || candidate.gameObject == null) continue;
|
||||
if (candidate.gameObject.name == "name")
|
||||
return candidate;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void SetDisplayName(string value)
|
||||
{
|
||||
string finalValue = value ?? string.Empty;
|
||||
if (nameText != null) nameText.text = finalValue;
|
||||
if (legacyNameText != null) legacyNameText.text = finalValue;
|
||||
}
|
||||
|
||||
private void ResolveHudExtras()
|
||||
{
|
||||
// These elements are part of the ally's UI hierarchy in the gameplay scene.
|
||||
@@ -959,8 +999,21 @@ public class AllyCombatant : MonoBehaviour, ICombatant
|
||||
private void InitializeStatsFromData()
|
||||
{
|
||||
bool dataFound = false;
|
||||
var uiController = teamUIController.Instance;
|
||||
int resolvedHeroId = ResolveAssignedHeroId();
|
||||
|
||||
if (uiController != null && resolvedHeroId > 0)
|
||||
{
|
||||
var preload = uiController.GetCurrentAllySOs();
|
||||
bool needsPopulate = preload == null || slotIndex < 0 || slotIndex >= preload.Length || preload[slotIndex] == null;
|
||||
if (needsPopulate)
|
||||
{
|
||||
uiController.PopulateAllySOsFromIds();
|
||||
}
|
||||
}
|
||||
|
||||
// Try TeamCharacterDataInfo first
|
||||
var arr = teamUIController.Instance?.GetCurrentAllySOs();
|
||||
var arr = uiController?.GetCurrentAllySOs();
|
||||
if (arr != null && slotIndex >= 0 && slotIndex < arr.Length)
|
||||
{
|
||||
var so = arr[slotIndex];
|
||||
@@ -972,9 +1025,9 @@ public class AllyCombatant : MonoBehaviour, ICombatant
|
||||
{
|
||||
maxHP = so.CharacterMaxHealth;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(so.CharacterName) && nameText != null)
|
||||
if (!string.IsNullOrEmpty(so.CharacterName))
|
||||
{
|
||||
nameText.text = so.CharacterName;
|
||||
SetDisplayName(so.CharacterName);
|
||||
}
|
||||
if (characterImage != null && so.CharacterImage_gameplay != null)
|
||||
{
|
||||
@@ -984,9 +1037,7 @@ public class AllyCombatant : MonoBehaviour, ICombatant
|
||||
}
|
||||
|
||||
// If more detailed info exists in AllyHero_SO, try to load by ally ID
|
||||
int id = -1;
|
||||
if (teamUIController.Instance != null && teamUIController.Instance.allySlotIds != null && slotIndex < teamUIController.Instance.allySlotIds.Count)
|
||||
id = teamUIController.Instance.allySlotIds[slotIndex];
|
||||
int id = resolvedHeroId;
|
||||
|
||||
if (id > 0)
|
||||
{
|
||||
@@ -1030,7 +1081,7 @@ public class AllyCombatant : MonoBehaviour, ICombatant
|
||||
}
|
||||
}
|
||||
|
||||
if (nameText != null) nameText.text = a.ally_heroName;
|
||||
SetDisplayName(a.ally_heroName);
|
||||
if (characterImage != null && a.ally_heroProfile != null) characterImage.sprite = a.ally_heroProfile;
|
||||
break;
|
||||
}
|
||||
@@ -1044,12 +1095,39 @@ public class AllyCombatant : MonoBehaviour, ICombatant
|
||||
currentHP = 0;
|
||||
maxMana = 0;
|
||||
currentMana = 0;
|
||||
if (nameText != null) nameText.text = "——";
|
||||
SetDisplayName("——");
|
||||
// Ensure UI shows -/- immediately
|
||||
UpdateUIImmediate();
|
||||
}
|
||||
}
|
||||
|
||||
private int ResolveAssignedHeroId()
|
||||
{
|
||||
var ui = teamUIController.Instance;
|
||||
if (ui != null && ui.allySlotIds != null && slotIndex >= 0 && slotIndex < ui.allySlotIds.Count)
|
||||
{
|
||||
int assigned = ui.allySlotIds[slotIndex];
|
||||
if (assigned > 0) return assigned;
|
||||
}
|
||||
|
||||
int prefsSlot = Mathf.Clamp(slotIndex + 1, 1, 5);
|
||||
int fallback = PlayerPrefs.GetInt($"selected_heroSlot0{prefsSlot}_heroID", 0);
|
||||
if (fallback > 0 && ui != null)
|
||||
{
|
||||
if (ui.allySlotIds == null || ui.allySlotIds.Count < 5)
|
||||
{
|
||||
ui.allySlotIds = new List<int> { 0, 0, 0, 0, 0 };
|
||||
}
|
||||
|
||||
if (slotIndex >= 0 && slotIndex < ui.allySlotIds.Count)
|
||||
{
|
||||
ui.allySlotIds[slotIndex] = fallback;
|
||||
}
|
||||
}
|
||||
|
||||
return fallback;
|
||||
}
|
||||
|
||||
private static void EnsureAllyHeroCache()
|
||||
{
|
||||
if (cachedAllAllyHeroes != null) return;
|
||||
|
||||
Reference in New Issue
Block a user