1
This commit is contained in:
@@ -8,7 +8,6 @@ using System.Net;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using UnityEngine.Video;
|
||||
//ui面板枚举 这里要求分类 Main *00 *00-*99 整数为主界面尾数为子界面
|
||||
public enum UIPanel
|
||||
{
|
||||
@@ -98,8 +97,6 @@ public enum UIPanel
|
||||
/// <summary>过场/加载面板接口(热更侧 LoadingPanel 实现)</summary>
|
||||
public interface ILoadingPanel
|
||||
{
|
||||
/// <summary>设置并播放过场视频</summary>
|
||||
void PlayVideo(VideoClip clip);
|
||||
/// <summary>设置背景图</summary>
|
||||
void SetBackground(Sprite sprite);
|
||||
/// <summary>注册播放结束回调</summary>
|
||||
@@ -202,14 +199,19 @@ public class UIManager : MonoSingleton<UIManager>
|
||||
_loadingShown = true;
|
||||
}
|
||||
|
||||
public ILoadingPanel ShowLoadPanel(VideoClip videoClip, Action action=null)
|
||||
/// <summary>
|
||||
/// 显示过场/加载面板(视频版)。
|
||||
/// 过场视频不再由加载面板自己播放:LoginPanel 根节点的 VideoPlayer 会把视频投影到
|
||||
/// 共享 RenderTexture(LoadBG),加载面板只是显示这张 RT,所以加载界面与登录界面
|
||||
/// 用的是同一个 VideoPlayer、同一进度,衔接时不会出现偏差。
|
||||
/// </summary>
|
||||
public ILoadingPanel ShowLoadPanel(Action action=null)
|
||||
{
|
||||
ShowAsync(UIPanel.LoginPanel);
|
||||
|
||||
GameObject load = Instantiate(loadPanel, uiRoot);
|
||||
var loadScript = load.GetComponent<ILoadingPanel>();
|
||||
load.transform.GetChild(0).gameObject.SetActive(true);
|
||||
loadScript.PlayVideo(videoClip);
|
||||
loadScript.SetOnEnd(action);
|
||||
return loadScript;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ using UnityEngine.InputSystem;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Video;
|
||||
|
||||
public class GameManager : MonoSingleton<GameManager>
|
||||
{
|
||||
@@ -586,7 +585,6 @@ public class GameManager : MonoSingleton<GameManager>
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
public Button btn_Skip;
|
||||
public VideoClip startVideoClip;
|
||||
|
||||
IEnumerator yanchi(ILoadingPanel loadingPanel)
|
||||
{
|
||||
@@ -600,16 +598,12 @@ public class GameManager : MonoSingleton<GameManager>
|
||||
void Start()
|
||||
{
|
||||
btn_Skip.gameObject.SetActive(false);
|
||||
var v = UIManager.Instance.ShowLoadPanel(startVideoClip);
|
||||
//UIManager.Instance.ShowAsync(UIPanel.LoginPanel, null, (a) =>
|
||||
//{
|
||||
// v.LoadBar(100);
|
||||
//}, 28);
|
||||
// 过场视频由 LoginPanel 根节点的 VideoPlayer 投影到共享 RT,加载面板只是显示它
|
||||
var v = UIManager.Instance.ShowLoadPanel();
|
||||
StartCoroutine(yanchi(v));
|
||||
btn_Skip.onClick.AddListener(() =>
|
||||
{
|
||||
UIManager.Instance.StopShowPanel();
|
||||
//UIManager.Instance.ShowAsync(UIPanel.LoginPanel, null, null, 0);
|
||||
v.LoadBar(100);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -61,7 +61,6 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 4e3d181187b8960468a09681396cff23, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
player: {fileID: 0}
|
||||
image_Bg: {fileID: 3732645741845648369}
|
||||
fadeTime: 1.3
|
||||
--- !u!223 &-8634983503678138505
|
||||
|
||||
@@ -1,23 +1,26 @@
|
||||
using DG.Tweening;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Video;
|
||||
|
||||
public class LoadingPanel : MonoBehaviour, ILoadingPanel
|
||||
{
|
||||
public VideoPlayer player;
|
||||
public Image image_Bg;
|
||||
public Action actionEnd;
|
||||
public float fadeTime = 1.3f;
|
||||
|
||||
/// <summary>设置并播放过场视频</summary>
|
||||
public void PlayVideo(VideoClip clip)
|
||||
/// <summary>过场视频显示的 RawImage(LoadPanel 预制体子节点 0),显示 LoginPanel VideoPlayer 投影的共享 RenderTexture</summary>
|
||||
private RawImage videoImage;
|
||||
|
||||
/// <summary>LoginPanel 根节点上播放过场视频的 VideoPlayer(加载面板只是显示它的输出,不自己播放)</summary>
|
||||
private VideoPlayer loginVideo;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
player.clip = clip;
|
||||
player.Play();
|
||||
if (transform.childCount > 0)
|
||||
videoImage = transform.GetChild(0).GetComponent<RawImage>();
|
||||
}
|
||||
|
||||
/// <summary>设置背景图</summary>
|
||||
@@ -38,14 +41,15 @@ public class LoadingPanel : MonoBehaviour, ILoadingPanel
|
||||
// 登录成功 UILoginPanel.Succeed() 的 ShowAsync(HomeMainPanel) 命中缓存秒开,
|
||||
// 不再出现"登录成功后进大厅白等"。
|
||||
StartCoroutine(PreloadHomeMainRoutine());
|
||||
StartCoroutine(BindLoginVideoRoutine());
|
||||
}
|
||||
|
||||
/// <summary>先让视频起播,播放过程中再预载大厅主面板(避免大包解压和视频启动抢主线程)</summary>
|
||||
/// <summary>播放过程中预载大厅主面板(避免大包解压和视频启动抢主线程)</summary>
|
||||
private IEnumerator PreloadHomeMainRoutine()
|
||||
{
|
||||
// 1) 等视频真正开始播放(最多等 5 秒兜底,防止视频未播时死等)
|
||||
// 1) 等共享过场视频(LoginPanel 根节点 VideoPlayer)真正起播(最多等 5 秒兜底,防止视频未播时死等)
|
||||
float waited = 0f;
|
||||
while (player != null && !player.isPlaying && waited < 5f)
|
||||
while ((loginVideo == null || !loginVideo.isPlaying) && waited < 5f)
|
||||
{
|
||||
waited += Time.deltaTime;
|
||||
yield return null;
|
||||
@@ -58,6 +62,44 @@ public class LoadingPanel : MonoBehaviour, ILoadingPanel
|
||||
UIManager.Instance.PreloadPanel(UIPanel.HomeMainPanel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 过场视频由 LoginPanel 根节点的 VideoPlayer 播放并投影到共享 RenderTexture,
|
||||
/// 这里等它就绪后监听 loopPointReached:视频第一遍循环播放完毕时隐藏跳过按钮。
|
||||
/// (面板销毁时协程终止;OnDestroy 里也会解除监听)
|
||||
/// </summary>
|
||||
private IEnumerator BindLoginVideoRoutine()
|
||||
{
|
||||
while (loginVideo == null)
|
||||
{
|
||||
yield return null;
|
||||
if (UIManager.Instance == null) continue;
|
||||
var login = UIManager.Instance.Get<UIBase>(UIPanel.LoginPanel);
|
||||
if (login == null) continue;
|
||||
loginVideo = login.GetComponent<VideoPlayer>();
|
||||
}
|
||||
loginVideo.loopPointReached += OnFirstLoopPointReached;
|
||||
}
|
||||
|
||||
/// <summary>视频第一遍播完:隐藏跳过按钮并解除监听</summary>
|
||||
private void OnFirstLoopPointReached(VideoPlayer vp)
|
||||
{
|
||||
vp.loopPointReached -= OnFirstLoopPointReached;
|
||||
loginVideo = null;
|
||||
HideSkipButton();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (loginVideo != null)
|
||||
loginVideo.loopPointReached -= OnFirstLoopPointReached;
|
||||
}
|
||||
|
||||
private void HideSkipButton()
|
||||
{
|
||||
if (GameManager.Instance != null && GameManager.Instance.btn_Skip != null)
|
||||
GameManager.Instance.btn_Skip.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 进入条进度值
|
||||
/// </summary>
|
||||
@@ -69,19 +111,19 @@ public class LoadingPanel : MonoBehaviour, ILoadingPanel
|
||||
// ⭐ 兜底再预载一次:若启动时 UIManager 尚未就绪导致首次发起无效,这里补上
|
||||
if (UIManager.Instance != null)
|
||||
UIManager.Instance.PreloadPanel(UIPanel.HomeMainPanel);
|
||||
GameManager.Instance.btn_Skip.gameObject.SetActive(false);
|
||||
|
||||
HideSkipButton();
|
||||
|
||||
Destroy(gameObject, fadeTime);
|
||||
if (player.gameObject.activeSelf)
|
||||
if (videoImage != null && videoImage.gameObject.activeSelf)
|
||||
{
|
||||
player.GetComponent<RawImage>().DOFade(0, fadeTime);
|
||||
videoImage.DOFade(0, fadeTime);
|
||||
}
|
||||
if (image_Bg.gameObject.activeSelf)
|
||||
if (image_Bg != null && image_Bg.gameObject.activeSelf)
|
||||
{
|
||||
image_Bg.DOFade(0, fadeTime);
|
||||
|
||||
}
|
||||
actionEnd?.Invoke();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user