using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;

public class ToastHandler : MonoBehaviour
{
    public Image image;
    public Text text;
    public int moveY;
    //初始化
    public void InitToast(string str, System.Action callback)
    {
        text.text = str;
        int StrLenth = str.Length;
        int ToastWidth = 1;
        int ToastHeight = 1;
        if (StrLenth > 10)
        {
            ToastHeight = (StrLenth / 10) + 1;
            ToastWidth = 10;
        }
        else
        {
            ToastWidth = StrLenth;
        }

        //image.rectTransform.sizeDelta = new Vector2(50 * ToastWidth + 100, 50 * ToastHeight + 100);
        FadeOut(callback);
    }

    public void FadeOut(System.Action callback)
    {
        Tweener tweener2 = image.DOFade(0, 1).OnComplete(() => {
            callback.Invoke();
            Destroy(gameObject);
        });
        Tweener tweener3 = text.DOFade(0, 1);
        tweener2.SetDelay(1f);
        tweener3.SetDelay(1f);
    }

    //堆叠向上移动
    public void Move(float speed, int targetPos)
    {
        //Tweener tweener = transform.DOLocalMoveY(moveY, speed);
        //tweener.SetDelay(0.2f);
    }
}
