85 lines
2.3 KiB
C#
85 lines
2.3 KiB
C#
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";
|
|
}
|
|
|
|
scoreManager = FindFirstObjectByType<ScoreManager>();
|
|
ApplyPopupTextStyle();
|
|
|
|
}
|
|
|
|
public void ShowScore()
|
|
{
|
|
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 );
|
|
}).SetOnComplete(delegate
|
|
{
|
|
scoreText.text = scoreManager.BuildResultSummary(length);
|
|
});
|
|
}
|
|
|
|
public void ResetValues()
|
|
{
|
|
gameObject.CancelAllTweens();
|
|
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;
|
|
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
}
|
|
}
|