2024-11-17 15:36:08 +00:00
|
|
|
using BlueWater.Audios;
|
2024-11-07 09:13:54 +00:00
|
|
|
using BlueWater.Tycoons;
|
2024-07-20 11:32:54 +00:00
|
|
|
using DG.Tweening;
|
|
|
|
using TMPro;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace BlueWater.Uis
|
|
|
|
{
|
|
|
|
public class PayMoneyUi : MonoBehaviour
|
|
|
|
{
|
2024-11-07 09:13:54 +00:00
|
|
|
[SerializeField]
|
|
|
|
private RectTransform _rect;
|
2024-07-20 11:32:54 +00:00
|
|
|
|
2024-11-07 09:13:54 +00:00
|
|
|
[SerializeField]
|
|
|
|
private TMP_Text _text;
|
2024-07-20 11:32:54 +00:00
|
|
|
|
2024-11-07 09:13:54 +00:00
|
|
|
[SerializeField]
|
|
|
|
private ParticleSystem _payMoneyParticle;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private float _offsetY = 1f;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private float _duration = 2f;
|
2024-11-17 15:36:08 +00:00
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private string _gainGoldSfxName = "GainGold";
|
2024-11-07 09:13:54 +00:00
|
|
|
|
2024-11-17 15:36:08 +00:00
|
|
|
public void Initialize(int gold, bool isTip, float duration = -1f)
|
2024-07-20 11:32:54 +00:00
|
|
|
{
|
2024-11-17 15:36:08 +00:00
|
|
|
float newDuration = duration >= 0f ? duration : _duration;
|
|
|
|
|
2024-11-15 07:28:13 +00:00
|
|
|
EventManager.InvokeAddedGold(gold, isTip);
|
2024-11-07 09:13:54 +00:00
|
|
|
_text.text = gold.ToString("N0");
|
|
|
|
|
|
|
|
_rect.localRotation = Quaternion.identity;
|
|
|
|
var endPosition = _rect.localPosition + new Vector3(0, _offsetY, 0);
|
|
|
|
var payMoneyParticle = Instantiate(_payMoneyParticle, transform.position,
|
|
|
|
_payMoneyParticle.transform.rotation);
|
|
|
|
payMoneyParticle.Play();
|
2024-11-17 15:36:08 +00:00
|
|
|
AudioManager.Instance.PlaySfx(_gainGoldSfxName);
|
2024-10-06 23:41:09 +00:00
|
|
|
|
2024-11-07 09:13:54 +00:00
|
|
|
var tween = DOTween.Sequence().SetAutoKill(true);
|
2024-11-17 15:36:08 +00:00
|
|
|
tween.Append(_rect.DOLocalMoveY(endPosition.y, newDuration).SetEase(Ease.InOutSine));
|
|
|
|
tween.Join(_rect.DOScale(Vector3.zero, newDuration).SetEase(Ease.InBack));
|
2024-11-07 09:13:54 +00:00
|
|
|
|
|
|
|
tween.OnComplete(() => Destroy(gameObject));
|
|
|
|
}
|
2024-07-20 11:32:54 +00:00
|
|
|
}
|
|
|
|
}
|