TipText.cs 916 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Collections;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. namespace WildAttack
  5. {
  6. public class TipText : MonoBehaviour
  7. {
  8. private static TipText _Instance;
  9. void Awake()
  10. {
  11. _Instance = this;
  12. gameObject.SetActive(false);
  13. }
  14. void Notify(string text)
  15. {
  16. gameObject.SetActive(true);
  17. GetComponentInChildren<Text>().text = text;
  18. LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>());
  19. StopCoroutine("DelayHide");
  20. StartCoroutine("DelayHide");
  21. }
  22. IEnumerator DelayHide()
  23. {
  24. yield return new WaitForSeconds(3);
  25. gameObject.SetActive(false);
  26. }
  27. public static void Show(string text)
  28. {
  29. if (_Instance) _Instance.Notify("<color=#2FFFEC>提示</color>\n" + text);
  30. }
  31. }
  32. }