技能主要更新,修复卡顿并加入动画,以及各种其他更新。
This commit is contained in:
@@ -32,6 +32,17 @@ public class ScoreManager : MonoBehaviour
|
||||
|
||||
private int[] idolScoreSums = new int[5];
|
||||
|
||||
private readonly int[] tmpCurrents = new int[5];
|
||||
private readonly int[] tmpMaxes = new int[5];
|
||||
|
||||
private readonly GameObject[] allyObjects = new GameObject[5];
|
||||
private readonly AllyCombatant[] allyCombatants = new AllyCombatant[5];
|
||||
private int lastAllyCacheFrame = -9999;
|
||||
|
||||
private readonly TextMeshProUGUI[] slotTmpFallback = new TextMeshProUGUI[5];
|
||||
private readonly Text[] slotLegacyFallback = new Text[5];
|
||||
private readonly bool[] slotFallbackResolved = new bool[5];
|
||||
|
||||
[Header("Judgement Statistics")]
|
||||
public int countPerfect = 0;
|
||||
public int countGreat = 0;
|
||||
@@ -93,6 +104,43 @@ public class ScoreManager : MonoBehaviour
|
||||
ResetStatistics();
|
||||
}
|
||||
|
||||
private void EnsureAllyCache()
|
||||
{
|
||||
int frame = Time.frameCount;
|
||||
if (frame - lastAllyCacheFrame < 30) return;
|
||||
lastAllyCacheFrame = frame;
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
if (allyCombatants[i] != null) continue;
|
||||
|
||||
var go = allyObjects[i];
|
||||
if (go == null)
|
||||
{
|
||||
go = GameObject.Find($"ally_0{i + 1}");
|
||||
allyObjects[i] = go;
|
||||
}
|
||||
if (go != null)
|
||||
{
|
||||
allyCombatants[i] = go.GetComponent<AllyCombatant>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ResolveSlotFallbackUi(int slotIndex, GameObject parent)
|
||||
{
|
||||
if (slotIndex < 0 || slotIndex >= 5) return;
|
||||
if (slotFallbackResolved[slotIndex]) return;
|
||||
if (parent == null) return;
|
||||
|
||||
slotTmpFallback[slotIndex] = parent.GetComponentInChildren<TextMeshProUGUI>(true);
|
||||
if (slotTmpFallback[slotIndex] == null)
|
||||
{
|
||||
slotLegacyFallback[slotIndex] = parent.GetComponentInChildren<Text>(true);
|
||||
}
|
||||
slotFallbackResolved[slotIndex] = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a per-note pm score delta to the specified track (0..4) and update named fields + aggregate.
|
||||
/// Also calculates idol score as pmDelta * scoreEfficiency.
|
||||
@@ -133,7 +181,8 @@ public class ScoreManager : MonoBehaviour
|
||||
allSum_pmScore = (int)Mathf.Min((float)aggPm, (float)int.MaxValue - 1f);
|
||||
allSum_idolScore = (int)Mathf.Min((float)aggIdol, (float)int.MaxValue - 1f);
|
||||
|
||||
Debug.Log($"[ScoreManager] Added {pmDelta} to track {trackIndex} pm sum, idol delta {idolDelta}. New pm sums: R{red_pmScore_sum} G{green_pmScore_sum} Y{yellow_pmScore_sum} P{purple_pmScore_sum} B{blue_pmScore_sum} -> allSumPm={allSum_pmScore}. Idol sums: R{red_idolScore_sum} G{green_idolScore_sum} Y{yellow_idolScore_sum} P{purple_idolScore_sum} B{blue_idolScore_sum} -> allSumIdol={allSum_idolScore}");
|
||||
if (JudgeManager.IsDebugEnabled)
|
||||
Debug.Log($"[ScoreManager] Added {pmDelta} to track {trackIndex} pm sum, idol delta {idolDelta}. New pm sums: R{red_pmScore_sum} G{green_pmScore_sum} Y{yellow_pmScore_sum} P{purple_pmScore_sum} B{blue_pmScore_sum} -> allSumPm={allSum_pmScore}. Idol sums: R{red_idolScore_sum} G{green_idolScore_sum} Y{yellow_idolScore_sum} P{purple_idolScore_sum} B{blue_idolScore_sum} -> allSumIdol={allSum_idolScore}");
|
||||
|
||||
// Update UI in teamUIController if available (per-track pm sums + aggregate)
|
||||
var ui = teamUIController.Instance;
|
||||
@@ -158,7 +207,7 @@ public class ScoreManager : MonoBehaviour
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
Debug.LogWarning($"[ScoreManager] Failed to write sums to teamUIController fields: {ex}");
|
||||
if (JudgeManager.IsDebugEnabled) Debug.LogWarning($"[ScoreManager] Failed to write sums to teamUIController fields: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,26 +219,20 @@ public class ScoreManager : MonoBehaviour
|
||||
|
||||
public void RecalculateTotal()
|
||||
{
|
||||
int sum = 0;
|
||||
int[] currents = new int[5];
|
||||
int[] maxes = new int[5];
|
||||
for (int i = 1; i <= 5; i++)
|
||||
EnsureAllyCache();
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
var go = GameObject.Find($"ally_0{i}");
|
||||
if (go == null) { currents[i - 1] = 0; maxes[i - 1] = 0; continue; }
|
||||
var ally = go.GetComponent<AllyCombatant>();
|
||||
var ally = allyCombatants[i];
|
||||
if (ally != null)
|
||||
{
|
||||
currents[i - 1] = ally.currentScore;
|
||||
maxes[i - 1] = ally.maxTrackScore;
|
||||
tmpCurrents[i] = ally.currentScore;
|
||||
tmpMaxes[i] = ally.maxTrackScore;
|
||||
}
|
||||
else
|
||||
{
|
||||
currents[i - 1] = 0;
|
||||
maxes[i - 1] = 0;
|
||||
tmpCurrents[i] = 0;
|
||||
tmpMaxes[i] = 0;
|
||||
}
|
||||
|
||||
sum += currents[i - 1];
|
||||
}
|
||||
|
||||
// totalScore should include both pm (per-note) and idol aggregates maintained by ScoreManager
|
||||
@@ -209,36 +252,62 @@ public class ScoreManager : MonoBehaviour
|
||||
if (assignedTmp != null)
|
||||
{
|
||||
assignedTmp.text = value;
|
||||
Debug.Log($"[ScoreManager] Wrote to assigned TMP for {slotName}: '{value}' -> {assignedTmp.gameObject.name}");
|
||||
if (JudgeManager.IsDebugEnabled) Debug.Log($"[ScoreManager] Wrote to assigned TMP for {slotName}: '{value}' -> {assignedTmp.gameObject.name}");
|
||||
return;
|
||||
}
|
||||
// try find TMP in parent
|
||||
if (parent != null)
|
||||
{
|
||||
var tmp = parent.GetComponentInChildren<TextMeshProUGUI>(true);
|
||||
if (tmp != null)
|
||||
int idx = slotName == "teammate01" ? 0 :
|
||||
slotName == "teammate02" ? 1 :
|
||||
slotName == "teammate03" ? 2 :
|
||||
slotName == "teammate04" ? 3 :
|
||||
slotName == "teammate05" ? 4 : -1;
|
||||
|
||||
if (idx >= 0)
|
||||
{
|
||||
tmp.text = value;
|
||||
Debug.Log($"[ScoreManager] Wrote to TMP in parent {parent.name} for {slotName}: '{value}' -> {tmp.gameObject.name}");
|
||||
return;
|
||||
ResolveSlotFallbackUi(idx, parent);
|
||||
var tmp = slotTmpFallback[idx];
|
||||
if (tmp != null)
|
||||
{
|
||||
tmp.text = value;
|
||||
if (JudgeManager.IsDebugEnabled) Debug.Log($"[ScoreManager] Wrote to TMP in parent {parent.name} for {slotName}: '{value}' -> {tmp.gameObject.name}");
|
||||
return;
|
||||
}
|
||||
var legacy = slotLegacyFallback[idx];
|
||||
if (legacy != null)
|
||||
{
|
||||
legacy.text = value;
|
||||
if (JudgeManager.IsDebugEnabled) Debug.Log($"[ScoreManager] Wrote to legacy Text in parent {parent.name} for {slotName}: '{value}' -> {legacy.gameObject.name}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
var legacy = parent.GetComponentInChildren<Text>(true);
|
||||
if (legacy != null)
|
||||
else
|
||||
{
|
||||
legacy.text = value;
|
||||
Debug.Log($"[ScoreManager] Wrote to legacy Text in parent {parent.name} for {slotName}: '{value}' -> {legacy.gameObject.name}");
|
||||
return;
|
||||
var tmp = parent.GetComponentInChildren<TextMeshProUGUI>(true);
|
||||
if (tmp != null)
|
||||
{
|
||||
tmp.text = value;
|
||||
if (JudgeManager.IsDebugEnabled) Debug.Log($"[ScoreManager] Wrote to TMP in parent {parent.name} for {slotName}: '{value}' -> {tmp.gameObject.name}");
|
||||
return;
|
||||
}
|
||||
var legacy = parent.GetComponentInChildren<Text>(true);
|
||||
if (legacy != null)
|
||||
{
|
||||
legacy.text = value;
|
||||
if (JudgeManager.IsDebugEnabled) Debug.Log($"[ScoreManager] Wrote to legacy Text in parent {parent.name} for {slotName}: '{value}' -> {legacy.gameObject.name}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
Debug.LogWarning($"[ScoreManager] Could not find UI to write score for {slotName}. assignedTmp is null and parent '{parent?.name}' has no TMP/Text children.");
|
||||
if (JudgeManager.IsDebugEnabled) Debug.LogWarning($"[ScoreManager] Could not find UI to write score for {slotName}. assignedTmp is null and parent '{parent?.name}' has no TMP/Text children.");
|
||||
}
|
||||
|
||||
// Update each slot: use the explicit TMP fields if set; otherwise try parent object fields
|
||||
SetScoreText(ui.teammate01_current_scoreText, ui.objectFather_ally01, currents[0], maxes[0], "teammate01");
|
||||
SetScoreText(ui.teammate02_current_scoreText, ui.objectFather_ally02, currents[1], maxes[1], "teammate02");
|
||||
SetScoreText(ui.teammate03_current_scoreText, ui.objectFather_ally03, currents[2], maxes[2], "teammate03");
|
||||
SetScoreText(ui.teammate04_current_scoreText, ui.objectFather_ally04, currents[3], maxes[3], "teammate04");
|
||||
SetScoreText(ui.teammate05_current_scoreText, ui.objectFather_ally05, currents[4], maxes[4], "teammate05");
|
||||
SetScoreText(ui.teammate01_current_scoreText, ui.objectFather_ally01, tmpCurrents[0], tmpMaxes[0], "teammate01");
|
||||
SetScoreText(ui.teammate02_current_scoreText, ui.objectFather_ally02, tmpCurrents[1], tmpMaxes[1], "teammate02");
|
||||
SetScoreText(ui.teammate03_current_scoreText, ui.objectFather_ally03, tmpCurrents[2], tmpMaxes[2], "teammate03");
|
||||
SetScoreText(ui.teammate04_current_scoreText, ui.objectFather_ally04, tmpCurrents[3], tmpMaxes[3], "teammate04");
|
||||
SetScoreText(ui.teammate05_current_scoreText, ui.objectFather_ally05, tmpCurrents[4], tmpMaxes[4], "teammate05");
|
||||
|
||||
// update total score (try TMP first, then legacy Text)
|
||||
if (ui.currentTotalScore != null)
|
||||
@@ -250,7 +319,7 @@ public class ScoreManager : MonoBehaviour
|
||||
if (tmpComp != null)
|
||||
{
|
||||
tmpComp.text = totalScore.ToString();
|
||||
Debug.Log($"[ScoreManager] Wrote total to TMP: {totalScore} -> {tmpComp.gameObject.name}");
|
||||
if (JudgeManager.IsDebugEnabled) Debug.Log($"[ScoreManager] Wrote total to TMP: {totalScore} -> {tmpComp.gameObject.name}");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -258,29 +327,29 @@ public class ScoreManager : MonoBehaviour
|
||||
if (legacyComp != null)
|
||||
{
|
||||
legacyComp.text = totalScore.ToString();
|
||||
Debug.Log($"[ScoreManager] Wrote total to legacy Text: {totalScore} -> {legacyComp.gameObject.name}");
|
||||
if (JudgeManager.IsDebugEnabled) Debug.Log($"[ScoreManager] Wrote total to legacy Text: {totalScore} -> {legacyComp.gameObject.name}");
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.currentTotalScore.text = totalScore.ToString(); // fallback
|
||||
Debug.Log($"[ScoreManager] Wrote total to currentTotalScore field fallback: {totalScore}");
|
||||
if (JudgeManager.IsDebugEnabled) Debug.Log($"[ScoreManager] Wrote total to currentTotalScore field fallback: {totalScore}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.currentTotalScore.text = totalScore.ToString();
|
||||
Debug.Log($"[ScoreManager] Wrote total to currentTotalScore fallback (no go): {totalScore}");
|
||||
if (JudgeManager.IsDebugEnabled) Debug.Log($"[ScoreManager] Wrote total to currentTotalScore fallback (no go): {totalScore}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[ScoreManager] teamUIController.currentTotalScore is null; cannot display total score.");
|
||||
if (JudgeManager.IsDebugEnabled) Debug.LogWarning("[ScoreManager] teamUIController.currentTotalScore is null; cannot display total score.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[ScoreManager] teamUIController.Instance is null; cannot update UI.");
|
||||
if (JudgeManager.IsDebugEnabled) Debug.LogWarning("[ScoreManager] teamUIController.Instance is null; cannot update UI.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user