HealthAdviceView.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections;
  2. using FairyGUI;
  3. using UI.Launcher;
  4. using UnityEngine;
  5. namespace GFGGame
  6. {
  7. public class HealthAdviceView : MonoBehaviour
  8. {
  9. private static GameObject _ui;
  10. /// <summary>
  11. /// 打开界面
  12. /// </summary>
  13. public static void Open()
  14. {
  15. // 启动异步加载协程
  16. CoroutineHelper.Instance.StartCoroutine(LoadUIHealthAdviceAsync());
  17. }
  18. private static IEnumerator LoadUIHealthAdviceAsync()
  19. {
  20. // 异步加载资源
  21. ResourceRequest request = Resources.LoadAsync<GameObject>("UUI/Launcher/UIHealthAdvice");
  22. yield return request; // 等待加载完成
  23. // 检查是否加载成功
  24. if (request.asset != null)
  25. {
  26. // 实例化加载的资源
  27. GameObject go = request.asset as GameObject;
  28. _ui = GameObject.Instantiate(go);
  29. }
  30. else
  31. {
  32. Debug.LogError("Failed to load UIHealthAdvice prefab.");
  33. }
  34. }
  35. /// <summary>
  36. /// 关闭界面
  37. /// </summary>
  38. /// <param name="toDestroy"></param>
  39. public static void Close()
  40. {
  41. GameObject.DestroyImmediate(_ui);
  42. _ui = null;
  43. //检测开启pad遮挡
  44. float maxAspectRatio = 1080 * 1.0f / 1920;
  45. if (Screen.width * 1.0f / Screen.height > maxAspectRatio)
  46. PadMaskView.Open();
  47. }
  48. }
  49. }