Super Knight : Enter the Dungeon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.8 KiB

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class Counting : MonoBehaviour
{
public TextMeshProUGUI tmpScore;
public Text txtScore;
bool PLAY = false;
public SoundPlayer spCounting;
[Space(10)]
public AnimationCurve curve;
public float duration = 1f;
[OnlyRead]
public float tick = 0.1f;
[Space(10)]
[OnlyRead]
public int value;
[Space(10)]
public int add = 100;
public void Redraw()
{
if (tmpScore != null) tmpScore.text = $"{value}";
if (txtScore != null) txtScore.text = $"{value}";
//txtScore.text = value == 0 ? "0" : $"{value:#,###}";
}
float timeSum = 0;
void Play()
{
timeSum += tick;
int add = (int)((valueEnd - valueStart) * curve.Evaluate(timeSum / duration));
if (timeSum < duration)
{
value = valueStart + add;
if(spCounting != null && 0 < add && PLAY)
SoundManager.Instance.EffectPlay(spCounting.gameObject);
}
else
{
value = valueEnd;
valueEnd = 0;
CancelInvoke();
}
Redraw();
}
int valueStart = 0;
int valueEnd = 0;
public void OnInitialized(int add, int cntDestroy, bool INIT = false, bool SOUND = false)
{
CancelInvoke();
if(INIT)
{
value = 0;
Redraw();
return;
}
PLAY = SOUND;
timeSum = 0;
valueStart = value;
if (valueEnd == 0)
valueEnd = value + add;
else
valueEnd += add;
tick = Time.deltaTime / duration;
InvokeRepeating("Play", tick, tick);
}
}