71 lines
1.2 KiB
C#
71 lines
1.2 KiB
C#
using DG.Tweening;
|
|
using Obvious.Soap;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class UI_MoneyBar : MonoBehaviour
|
|
{
|
|
public FloatVariable PlayerMoney;
|
|
|
|
[SerializeField]
|
|
private TextMeshProUGUI _MoneyText;
|
|
|
|
private float _Money;
|
|
|
|
private Animator _Animator;
|
|
|
|
private bool isPlayingTween;
|
|
|
|
private void Awake()
|
|
{
|
|
_Animator = GetComponent<Animator>();
|
|
_Animator.Play("Out");
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
_Money = PlayerMoney.Value;
|
|
UpdateText();
|
|
PlayerMoney.OnValueChanged += PlayerMoneyOnOnValueChanged;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
PlayerMoney.OnValueChanged -= PlayerMoneyOnOnValueChanged;
|
|
}
|
|
|
|
private void PlayerMoneyOnOnValueChanged(float money)
|
|
{
|
|
float t = 0f;
|
|
isPlayingTween = true;
|
|
_Animator.Play("In");
|
|
DOTween.To(() => _Money, delegate(float value)
|
|
{
|
|
_Money = value;
|
|
}, money, 1f).SetDelay(0.1f).OnUpdate(delegate
|
|
{
|
|
UpdateText();
|
|
})
|
|
.OnComplete(delegate
|
|
{
|
|
isPlayingTween = false;
|
|
})
|
|
.Play();
|
|
DOTween.To(() => t, delegate(float value)
|
|
{
|
|
t = value;
|
|
}, 5f, 5f).OnComplete(delegate
|
|
{
|
|
if (!isPlayingTween)
|
|
{
|
|
_Animator.Play("Out");
|
|
}
|
|
});
|
|
}
|
|
|
|
private void UpdateText()
|
|
{
|
|
_MoneyText.text = _Money.ToString("F") + "$";
|
|
}
|
|
}
|