51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.AddressableAssets;
|
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
|
using TMPro;
|
|
using DG.Tweening; // cần DOTween
|
|
using BrewMonster.Scripts.UI.GamePlay;
|
|
using UnityEngine.UI;
|
|
namespace BrewMonster.Scripts.UI.GamePlay
|
|
{
|
|
public class AUIFloatTextIcon : MonoBehaviour
|
|
{
|
|
[SerializeField] TMP_Text text;
|
|
[SerializeField] SpriteRenderer ingameIcon;
|
|
public void Show(Vector3 worldPos, string damage, Color color = default, float scale = 1f, float riseDistance = 1f, float riseDuration = 1f, Sprite sprite = null, Action onComplete = null)
|
|
{
|
|
if(sprite != null)
|
|
{
|
|
ingameIcon.sprite = sprite;
|
|
ingameIcon.gameObject.SetActive(true);
|
|
color = new Color(color.r/255f, color.g/255f, color.b/255f, 1f);
|
|
ingameIcon.color = color;
|
|
|
|
}
|
|
else
|
|
{
|
|
ingameIcon.gameObject.SetActive(false);
|
|
}
|
|
text.text = damage;
|
|
text.color = color;
|
|
text.fontSize = 6;
|
|
text.transform.localScale = Vector3.one * scale;
|
|
text.transform.position = worldPos;
|
|
gameObject.SetActive(true);
|
|
|
|
// Hiệu ứng bay lên + mờ dần
|
|
text.transform.DOMoveY(worldPos.y + riseDistance, riseDuration).SetEase(Ease.OutQuad);
|
|
text.DOFade(0f, riseDuration)
|
|
.SetEase(Ease.InQuad)
|
|
.OnComplete(() =>
|
|
{
|
|
text.alpha = 1f;
|
|
text.gameObject.SetActive(false);
|
|
onComplete?.Invoke();
|
|
});
|
|
}
|
|
}
|
|
|
|
}
|