69 lines
2.4 KiB
C#
69 lines
2.4 KiB
C#
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.Video;
|
|
|
|
public class LoadingPanel : MonoBehaviour
|
|
{
|
|
public VideoPlayer player;
|
|
public Image image_Bg;
|
|
public Action actionEnd;
|
|
public float fadeTime = 1.3f;
|
|
|
|
private void Start()
|
|
{
|
|
// ⭐ 视频播放期间预载大厅主面板:把 HomeUIRes 的加载提前到这段视频等待时间里,
|
|
// 登录成功 UILoginPanel.Succeed() 的 ShowAsync(HomeMainPanel) 命中缓存秒开,
|
|
// 不再出现"登录成功后进大厅白等"。
|
|
StartCoroutine(PreloadHomeMainRoutine());
|
|
}
|
|
|
|
/// <summary>先让视频起播,播放过程中再预载大厅主面板(避免大包解压和视频启动抢主线程)</summary>
|
|
private IEnumerator PreloadHomeMainRoutine()
|
|
{
|
|
// 1) 等视频真正开始播放(最多等 5 秒兜底,防止视频未播时死等)
|
|
float waited = 0f;
|
|
while (player != null && !player.isPlaying && waited < 5f)
|
|
{
|
|
waited += Time.deltaTime;
|
|
yield return null;
|
|
}
|
|
yield return new WaitForSeconds(0.5f); // 让视频先渲染几帧,起播更顺
|
|
// 2) 播放过程中加载:等 UIManager 就绪后发起预载
|
|
while (UIManager.Instance == null)
|
|
yield return null;
|
|
yield return null; // 等 UIManager 初始化完成(地址表装载)
|
|
UIManager.Instance.PreloadPanel(UIPanel.HomeMainPanel);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 进入条进度值
|
|
/// </summary>
|
|
/// <param name="count">最大100 100时直接删除</param>
|
|
public void LoadBar(int count)
|
|
{
|
|
if (count == 100)
|
|
{
|
|
// ⭐ 兜底再预载一次:若启动时 UIManager 尚未就绪导致首次发起无效,这里补上
|
|
if (UIManager.Instance != null)
|
|
UIManager.Instance.PreloadPanel(UIPanel.HomeMainPanel);
|
|
GameManager.Instance.btn_Skip.gameObject.SetActive(false);
|
|
Destroy(gameObject, fadeTime);
|
|
if (player.gameObject.activeSelf)
|
|
{
|
|
player.GetComponent<RawImage>().DOFade(0, fadeTime);
|
|
}
|
|
if (image_Bg.gameObject.activeSelf)
|
|
{
|
|
image_Bg.DOFade(0, fadeTime);
|
|
|
|
}
|
|
actionEnd?.Invoke();
|
|
}
|
|
|
|
}
|
|
}
|