| | |
| | | static StringBuilder stringBuild = new StringBuilder(); |
| | | private void UpdateSurplusSegments(float _targetValue) |
| | | { |
| | | var currentSurplus = Mathf.CeilToInt(_targetValue); |
| | | const float eps = 1e-5f; |
| | | // 添加这一行:如果值太小,直接当作 0 处理 |
| | | if (_targetValue < eps) _targetValue = 0f; |
| | | |
| | | var currentSurplus = _targetValue < eps ? 0 : Mathf.CeilToInt(_targetValue); |
| | | if (currentSurplus != surplusSegments) |
| | | { |
| | | surplusSegments = currentSurplus; |
| | |
| | | m_BackGround.SetActive(surplusSegments > 1); |
| | | |
| | | m_Surplus.text = "x" + surplusSegments.ToString(); |
| | | float pct = totalSegments > 0 ? Mathf.Clamp01(_targetValue / totalSegments) : 0f; |
| | | // 修改这里:使用 targetValue(最终目标值)而不是 _targetValue(当前过渡值) |
| | | float pct = totalSegments > 0 ? Mathf.Clamp01(targetValue / totalSegments) : 0f; |
| | | // 修复格式并处理接近 100% 的情况 |
| | | if (1f - pct < 0.00005f) pct = 1f; |
| | | m_SurplusPercent.text = (pct * 100f).ToString("F2") + "%"; |