TextSmartBowTip.cs 898 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System.Collections;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. namespace DuckHunter
  5. {
  6. public class TextSmartBowTip : MonoBehaviour
  7. {
  8. private static TextSmartBowTip _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(text);
  30. }
  31. }
  32. }