some updates
This commit is contained in:
@@ -53,6 +53,28 @@ public class ScoreManager : MonoBehaviour
|
||||
private readonly TextMeshProUGUI[] slotTmpFallback = new TextMeshProUGUI[5];
|
||||
private readonly Text[] slotLegacyFallback = new Text[5];
|
||||
private readonly bool[] slotFallbackResolved = new bool[5];
|
||||
|
||||
// 性能:缓存 currentTotalScore 的 TMP/Text 组件,避免每次判定 GetComponent。
|
||||
private TextMeshProUGUI _cachedTotalTmp;
|
||||
private Text _cachedTotalLegacy;
|
||||
private GameObject _cachedTotalGo;
|
||||
// 性能:记录上次写入 UI 的字符串,值未变则跳过 .text 赋值(避免 TMP 无谓网格重建)。
|
||||
private string _lastTotalText;
|
||||
// 性能:per-track pm/idol 合计上次写入值(12 项),值未变跳过 .text,避免每判定重写全部槽位触发网格重建。
|
||||
// 索引:0-5 = pm(red,green,yellow,purple,blue,all),6-11 = idol(同序)。int.MinValue 表示尚未写入。
|
||||
private readonly int[] _lastSumWritten = new int[12] {
|
||||
int.MinValue, int.MinValue, int.MinValue, int.MinValue, int.MinValue, int.MinValue,
|
||||
int.MinValue, int.MinValue, int.MinValue, int.MinValue, int.MinValue, int.MinValue
|
||||
};
|
||||
|
||||
// 仅当数值变化时写 TMP.text(避免相同字符串触发无谓网格重建)。
|
||||
private void SetSumTextIfChanged(TextMeshProUGUI field, int value, int cacheIndex)
|
||||
{
|
||||
if (field == null) return;
|
||||
if (_lastSumWritten[cacheIndex] == value) return;
|
||||
_lastSumWritten[cacheIndex] = value;
|
||||
field.text = value.ToString();
|
||||
}
|
||||
private JudgeManager hookedJudgeManager;
|
||||
private bool perfectBonusHooked = false;
|
||||
private int perfectClearBonusPm = 0;
|
||||
@@ -449,34 +471,22 @@ public class ScoreManager : MonoBehaviour
|
||||
if (ui != null)
|
||||
{
|
||||
// Legacy Text fields on teamUIController
|
||||
// 性能:仅在数值变化时写(SetSumTextIfChanged),避免每判定重写 12 个槽位触发 TMP 网格重建。
|
||||
try
|
||||
{
|
||||
string redPmText = red_pmScore_sum.ToString();
|
||||
string greenPmText = green_pmScore_sum.ToString();
|
||||
string yellowPmText = yellow_pmScore_sum.ToString();
|
||||
string purplePmText = purple_pmScore_sum.ToString();
|
||||
string bluePmText = blue_pmScore_sum.ToString();
|
||||
string allPmText = allSum_pmScore.ToString();
|
||||
string redIdolText = red_idolScore_sum.ToString();
|
||||
string greenIdolText = green_idolScore_sum.ToString();
|
||||
string yellowIdolText = yellow_idolScore_sum.ToString();
|
||||
string purpleIdolText = purple_idolScore_sum.ToString();
|
||||
string blueIdolText = blue_idolScore_sum.ToString();
|
||||
string allIdolText = allSum_idolScore.ToString();
|
||||
SetSumTextIfChanged(ui.red_pmScore_sum, red_pmScore_sum, 0);
|
||||
SetSumTextIfChanged(ui.green_pmScore_sum, green_pmScore_sum, 1);
|
||||
SetSumTextIfChanged(ui.yellow_pmScore_sum, yellow_pmScore_sum, 2);
|
||||
SetSumTextIfChanged(ui.purple_pmScore_sum, purple_pmScore_sum, 3);
|
||||
SetSumTextIfChanged(ui.blue_pmScore_sum, blue_pmScore_sum, 4);
|
||||
SetSumTextIfChanged(ui.allSum_pmScore, allSum_pmScore, 5);
|
||||
|
||||
if (ui.red_pmScore_sum != null) ui.red_pmScore_sum.text = redPmText;
|
||||
if (ui.green_pmScore_sum != null) ui.green_pmScore_sum.text = greenPmText;
|
||||
if (ui.yellow_pmScore_sum != null) ui.yellow_pmScore_sum.text = yellowPmText;
|
||||
if (ui.purple_pmScore_sum != null) ui.purple_pmScore_sum.text = purplePmText;
|
||||
if (ui.blue_pmScore_sum != null) ui.blue_pmScore_sum.text = bluePmText;
|
||||
if (ui.allSum_pmScore != null) ui.allSum_pmScore.text = allPmText;
|
||||
|
||||
if (ui.red_idolScore_sum != null) ui.red_idolScore_sum.text = redIdolText;
|
||||
if (ui.green_idolScore_sum != null) ui.green_idolScore_sum.text = greenIdolText;
|
||||
if (ui.yellow_idolScore_sum != null) ui.yellow_idolScore_sum.text = yellowIdolText;
|
||||
if (ui.purple_idolScore_sum != null) ui.purple_idolScore_sum.text = purpleIdolText;
|
||||
if (ui.blue_idolScore_sum != null) ui.blue_idolScore_sum.text = blueIdolText;
|
||||
if (ui.allSum_idolScore != null) ui.allSum_idolScore.text = allIdolText;
|
||||
SetSumTextIfChanged(ui.red_idolScore_sum, red_idolScore_sum, 6);
|
||||
SetSumTextIfChanged(ui.green_idolScore_sum, green_idolScore_sum, 7);
|
||||
SetSumTextIfChanged(ui.yellow_idolScore_sum, yellow_idolScore_sum, 8);
|
||||
SetSumTextIfChanged(ui.purple_idolScore_sum, purple_idolScore_sum, 9);
|
||||
SetSumTextIfChanged(ui.blue_idolScore_sum, blue_idolScore_sum, 10);
|
||||
SetSumTextIfChanged(ui.allSum_idolScore, allSum_idolScore, 11);
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
@@ -681,23 +691,33 @@ public class ScoreManager : MonoBehaviour
|
||||
var go = ui.currentTotalScore.gameObject;
|
||||
if (go != null)
|
||||
{
|
||||
var tmpComp = go.GetComponent<TextMeshProUGUI>();
|
||||
if (tmpComp != null)
|
||||
// 性能:仅在目标物体变化时 GetComponent(缓存),避免每次判定重复反射查找。
|
||||
if (_cachedTotalGo != go)
|
||||
{
|
||||
tmpComp.text = totalScore.ToString();
|
||||
if (JudgeManager.IsDebugEnabled) Debug.Log($"[ScoreManager] Wrote total to TMP: {totalScore} -> {tmpComp.gameObject.name}");
|
||||
_cachedTotalGo = go;
|
||||
_cachedTotalTmp = go.GetComponent<TextMeshProUGUI>();
|
||||
_cachedTotalLegacy = _cachedTotalTmp == null ? go.GetComponent<Text>() : null;
|
||||
_lastTotalText = null; // 目标物体变了(如新一局/换场景),强制写一次
|
||||
}
|
||||
else
|
||||
|
||||
string totalText = totalScore.ToString();
|
||||
// 性能:值未变则跳过 .text 赋值,避免 TMP 无谓网格重建。
|
||||
if (totalText != _lastTotalText)
|
||||
{
|
||||
var legacyComp = go.GetComponent<Text>();
|
||||
if (legacyComp != null)
|
||||
_lastTotalText = totalText;
|
||||
if (_cachedTotalTmp != null)
|
||||
{
|
||||
legacyComp.text = totalScore.ToString();
|
||||
if (JudgeManager.IsDebugEnabled) Debug.Log($"[ScoreManager] Wrote total to legacy Text: {totalScore} -> {legacyComp.gameObject.name}");
|
||||
_cachedTotalTmp.text = totalText;
|
||||
if (JudgeManager.IsDebugEnabled) Debug.Log($"[ScoreManager] Wrote total to TMP: {totalScore} -> {_cachedTotalTmp.gameObject.name}");
|
||||
}
|
||||
else if (_cachedTotalLegacy != null)
|
||||
{
|
||||
_cachedTotalLegacy.text = totalText;
|
||||
if (JudgeManager.IsDebugEnabled) Debug.Log($"[ScoreManager] Wrote total to legacy Text: {totalScore} -> {_cachedTotalLegacy.gameObject.name}");
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.currentTotalScore.text = totalScore.ToString(); // fallback
|
||||
ui.currentTotalScore.text = totalText; // fallback
|
||||
if (JudgeManager.IsDebugEnabled) Debug.Log($"[ScoreManager] Wrote total to currentTotalScore field fallback: {totalScore}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user