2025-07-02 10:05:26 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
|
using DG.Tweening;
|
|
|
|
|
|
using Stary.Evo;
|
|
|
|
|
|
using Stary.Evo.AudioCore;
|
|
|
|
|
|
using Stary.Evo.UIFarme;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
using UnityEngine.Video;
|
|
|
|
|
|
using YooAsset;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class VideoPanel : BasePanel
|
|
|
|
|
|
{
|
2025-09-02 14:15:18 +08:00
|
|
|
|
private Transform area;
|
2025-07-02 10:05:26 +08:00
|
|
|
|
private RawImage intro;
|
|
|
|
|
|
|
|
|
|
|
|
private GameObject prospect;
|
|
|
|
|
|
private GameObject bg;
|
|
|
|
|
|
|
|
|
|
|
|
private Animator _animator;
|
|
|
|
|
|
|
|
|
|
|
|
private VideoPlayer videoPlayer;
|
|
|
|
|
|
|
|
|
|
|
|
private AudioSource audioSource;
|
|
|
|
|
|
|
|
|
|
|
|
private RenderTexture renderTexture;
|
|
|
|
|
|
|
|
|
|
|
|
public VideoPanel()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override void Initialize(GameObject panelGo)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize(panelGo);
|
2025-09-02 14:15:18 +08:00
|
|
|
|
area = activePanel.transform.Find("Area");
|
|
|
|
|
|
intro = area.Find("Intro").GetComponent<RawImage>();
|
|
|
|
|
|
prospect = area.Find("prospect").gameObject;
|
|
|
|
|
|
bg = area.Find("bg").gameObject;
|
|
|
|
|
|
videoPlayer = area.GetComponentInChildren<VideoPlayer>();
|
|
|
|
|
|
audioSource = area.GetComponentInChildren<AudioSource>();
|
|
|
|
|
|
_animator = area.GetComponentInChildren<Animator>();
|
2025-07-02 10:05:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnEnter()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnEnter();
|
|
|
|
|
|
|
|
|
|
|
|
this.RegisterEvent<ModeType, VideoInfo>(ModeType.VideoStart, OnStartMove);
|
|
|
|
|
|
this.RegisterEvent<ModeType>(ModeType.VideoEnd, OnStopMove);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnExit(float delay = 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnExit(delay);
|
|
|
|
|
|
this.UnRegisterEvent<ModeType, VideoInfo>(ModeType.VideoStart, OnStartMove);
|
|
|
|
|
|
this.UnRegisterEvent<ModeType>(ModeType.VideoEnd, OnStopMove);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void OnStartMove(VideoInfo info)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (info.filename.Equals(""))
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogError("UnityEvo:视频文件名为空,必须传文件名才能执行");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (info.position != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
activePanel.transform.position = info.position.SetVector3Ctor();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (info.rotation != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
activePanel.transform.rotation = Quaternion.Euler(info.rotation.SetVector3Ctor());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (info.scale != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
activePanel.transform.DOScale(info.scale.SetVector3Ctor(), 0.5f);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-04 11:43:35 +08:00
|
|
|
|
OnStartMove(info.filename, info.videoframeName, info.callback, info.isFixedSize);
|
2025-07-02 10:05:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-09-04 11:43:35 +08:00
|
|
|
|
private async void OnStartMove(string fileName, string videoframeName, Action callback, bool isFixedSize)
|
2025-07-02 10:05:26 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (isFixedSize)
|
|
|
|
|
|
{
|
|
|
|
|
|
_animator.gameObject.SetActive(false);
|
|
|
|
|
|
bg.SetActive(false);
|
|
|
|
|
|
prospect.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_animator.gameObject.SetActive(true);
|
|
|
|
|
|
bg.SetActive(true);
|
|
|
|
|
|
prospect.SetActive(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-04 11:43:35 +08:00
|
|
|
|
var mainpackage = YooAssets.TryGetPackage("Main");
|
|
|
|
|
|
var videoframeHandle = mainpackage.LoadAssetAsync<Sprite>(videoframeName);
|
|
|
|
|
|
await videoframeHandle.Task;
|
|
|
|
|
|
bg.GetComponent<Image>().sprite = videoframeHandle.GetAssetObject<Sprite>();
|
2025-07-02 10:05:26 +08:00
|
|
|
|
|
|
|
|
|
|
//新增renderTexture创建
|
|
|
|
|
|
if (videoPlayer.isPlaying)
|
|
|
|
|
|
{
|
|
|
|
|
|
videoPlayer.Stop();
|
|
|
|
|
|
//释放renderTexture
|
|
|
|
|
|
if (renderTexture != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
renderTexture.Release();
|
|
|
|
|
|
renderTexture = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var videHandle = YooAssets.LoadAssetAsync<VideoClip>(fileName);
|
|
|
|
|
|
await videHandle.Task;
|
|
|
|
|
|
Debug.Log("UnityEvo:开始播放视频:" + fileName);
|
|
|
|
|
|
VideoClip videoClip = videHandle.GetAssetObject<VideoClip>();
|
|
|
|
|
|
|
|
|
|
|
|
renderTexture = new RenderTexture((int)videoClip.width, (int)videoClip.height, 24);
|
|
|
|
|
|
videoPlayer.targetTexture = renderTexture;
|
|
|
|
|
|
intro.texture = renderTexture;
|
|
|
|
|
|
intro.SetNativeSize();
|
|
|
|
|
|
var musicHandle = YooAssets.LoadAssetAsync<AudioClip>(fileName + "_mp3");
|
|
|
|
|
|
await musicHandle.Task;
|
|
|
|
|
|
|
|
|
|
|
|
videoPlayer.source = VideoSource.VideoClip;
|
|
|
|
|
|
videoPlayer.clip = videoClip;
|
|
|
|
|
|
|
|
|
|
|
|
Debug.Log("UnityEvo:开始播放视频的音频:" + fileName + "_mp3");
|
|
|
|
|
|
AudioClip audioClip = musicHandle.GetAssetObject<AudioClip>();
|
|
|
|
|
|
audioSource.clip = audioClip;
|
|
|
|
|
|
|
|
|
|
|
|
//等待视频加载完成
|
|
|
|
|
|
videoPlayer.Prepare();
|
|
|
|
|
|
videoPlayer.prepareCompleted += (source) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
_animator.Play("vid_maskAni", 0, 0);
|
|
|
|
|
|
|
|
|
|
|
|
//预加载
|
|
|
|
|
|
if (videoPlayer.isPrepared)
|
|
|
|
|
|
{
|
|
|
|
|
|
videoPlayer.Play();
|
|
|
|
|
|
audioSource.Play();
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
videoPlayer.loopPointReached += (source) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
OnStopMove();
|
|
|
|
|
|
callback?.Invoke();
|
|
|
|
|
|
};
|
|
|
|
|
|
videoPlayer.errorReceived += (source, error) => { Debug.LogError($"视频播放失败:{error}"); };
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnStopMove()
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log("UnityEvo:视频播放完成");
|
|
|
|
|
|
AudioCoreManager.SetMusicVolume(new AudioData()
|
|
|
|
|
|
{
|
|
|
|
|
|
fadeDuration = 2f,
|
|
|
|
|
|
volume = 1f,
|
|
|
|
|
|
});
|
|
|
|
|
|
_animator.Play("vid_maskDefault", 0, 0);
|
|
|
|
|
|
if (renderTexture != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
renderTexture.Release();
|
|
|
|
|
|
renderTexture = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (audioSource.isPlaying)
|
|
|
|
|
|
{
|
|
|
|
|
|
audioSource.Stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PanelSystem.PopQueue<VideoPanel>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public struct VideoInfo
|
|
|
|
|
|
{
|
|
|
|
|
|
public string filename;
|
2025-09-04 11:43:35 +08:00
|
|
|
|
public string videoframeName;
|
2025-07-02 10:05:26 +08:00
|
|
|
|
public Vector3Ctor position;
|
|
|
|
|
|
public Vector3Ctor rotation;
|
|
|
|
|
|
public Vector3Ctor scale;
|
|
|
|
|
|
public Action callback;
|
|
|
|
|
|
public bool isFixedSize;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|