Files
BeatSaber/Assets/VRBeatsKit/Scripts/UI/FinalScoreLabel.cs
T

85 lines
2.3 KiB
C#
Raw Normal View History

using UnityEngine;
using Platinio.TweenEngine;
using TMPro;
namespace VRBeats
{
public class FinalScoreLabel : MonoBehaviour
{
[SerializeField] private TextMeshProUGUI scoreText = null;
[SerializeField] private float scoreFadeTime = 10.0f;
[SerializeField] private int length = 10;
private string initialValue = "";
private ScoreManager scoreManager = null;
private void Awake()
{
for (int n = 0; n < length; n++)
{
initialValue += "0";
}
2026-05-26 18:54:56 +09:00
scoreManager = FindFirstObjectByType<ScoreManager>();
2026-05-28 19:01:20 +09:00
ApplyPopupTextStyle();
}
public void ShowScore()
{
2026-05-28 19:01:20 +09:00
if (scoreText == null || scoreManager == null)
return;
PlatinioTween.instance.ValueTween( 0.0f , scoreManager.CurrentScore , Mathf.Min(scoreFadeTime, 0.8f)).SetOnUpdateFloat(delegate (float v)
{
SetScore( (int)v );
2026-05-28 19:01:20 +09:00
}).SetOnComplete(delegate
{
scoreText.text = scoreManager.BuildResultSummary(length);
});
}
public void ResetValues()
{
gameObject.CancelAllTweens();
2026-05-28 19:01:20 +09:00
ApplyPopupTextStyle();
if (scoreText != null)
scoreText.text = initialValue;
}
private void SetScore(int score)
{
if (this.scoreText == null)
return;
string scoreText = score.ToString();
int addLength = Mathf.Max( length - scoreText.Length , 0);
string addZeros = "";
for (int n = 0; n < addLength; n++)
{
addZeros += "0";
}
this.scoreText.text = addZeros + scoreText;
}
2026-05-28 19:01:20 +09:00
private void ApplyPopupTextStyle()
{
if (scoreText == null)
return;
scoreText.enableAutoSizing = false;
scoreText.fontSize = 4.4f;
scoreText.alignment = TextAlignmentOptions.Center;
scoreText.overflowMode = TextOverflowModes.Overflow;
scoreText.textWrappingMode = TextWrappingModes.NoWrap;
scoreText.lineSpacing = -18.0f;
scoreText.color = Color.white;
scoreText.richText = true;
}
}
}