using System.Collections;
using UnityEngine;
using UnityEngine.UI;

public class TipText : MonoBehaviour
{
    private static TipText _Instance;

    void Awake()
    {
        _Instance = this;
        gameObject.SetActive(false);
    }

    void Notify(string text)
    {
        gameObject.SetActive(true);
        GetComponentInChildren<Text>().text = text;
        LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>());
        StopCoroutine("DelayHide");
        StartCoroutine("DelayHide");
    }

    IEnumerator DelayHide()
    {
        yield return new WaitForSeconds(3);
        gameObject.SetActive(false);
    }

    public static void Show(string text)
    {
        if (_Instance) _Instance.Notify("<color=#2FFFEC>提示</color>\n" + text);
    }
}
