| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using System.Collections;
- using FairyGUI;
- using UI.Launcher;
- using UnityEngine;
- namespace GFGGame
- {
- public class HealthAdviceView : MonoBehaviour
- {
- private static GameObject _ui;
- /// <summary>
- /// 打开界面
- /// </summary>
- public static void Open()
- {
- // 启动异步加载协程
- CoroutineHelper.Instance.StartCoroutine(LoadUIHealthAdviceAsync());
- }
-
- private static IEnumerator LoadUIHealthAdviceAsync()
- {
- // 异步加载资源
- ResourceRequest request = Resources.LoadAsync<GameObject>("UUI/Launcher/UIHealthAdvice");
- yield return request; // 等待加载完成
- // 检查是否加载成功
- if (request.asset != null)
- {
- // 实例化加载的资源
- GameObject go = request.asset as GameObject;
- _ui = GameObject.Instantiate(go);
- }
- else
- {
- Debug.LogError("Failed to load UIHealthAdvice prefab.");
- }
- }
- /// <summary>
- /// 关闭界面
- /// </summary>
- /// <param name="toDestroy"></param>
- public static void Close()
- {
- GameObject.DestroyImmediate(_ui);
- _ui = null;
- //检测开启pad遮挡
- float maxAspectRatio = 1080 * 1.0f / 1920;
- if (Screen.width * 1.0f / Screen.height > maxAspectRatio)
- PadMaskView.Open();
- }
- }
- }
|