Files
ft/Client/Assets/Scripts/MatchGame/UI/EventMatchNpcLeviathanPresenter.cs
2026-06-29 21:18:33 +08:00

91 lines
2.6 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UniRx;
using UnityEngine;
/// <summary>
/// Leviathan 视频 NPC待机循环、成功/大三消各一段一次性视频,资源在本组件上拖拽(不必再依赖解码器上的 bytesFile
/// </summary>
public class EventMatchNpcLeviathanPresenter : EventMatchNpcPresenter
{
[SerializeField] LeviathanVideoDecoderBase decoder;
[SerializeField] TextAsset idleVideo;
[SerializeField] TextAsset successVideo;
[SerializeField] TextAsset successMoreVideo;
void Awake()
{
if (decoder == null)
decoder = GetComponent<LeviathanVideoDecoder>();
}
void Start()
{
if (decoder == null)
return;
decoder.Stop();
PlayIdleInternal();
}
void OnDestroy()
{
if (decoder != null)
decoder.OnPlayCompleted -= OnSuccessClipCompleted;
}
/// <summary>
/// 多线程解码时 OnPlayCompleted 可能来自解码线程,需回到主线程再 Stop/PlayVideo。
/// </summary>
void OnSuccessClipCompleted()
{
if (decoder != null)
decoder.OnPlayCompleted -= OnSuccessClipCompleted;
MainThreadDispatcher.Post(_ => ApplySuccessFinishedOnMainThread(), null);
}
void ApplySuccessFinishedOnMainThread()
{
if (this == null)
return;
PlayIdleInternal();
}
void PlaySuccessClipInternal(TextAsset clip)
{
decoder.OnPlayCompleted -= OnSuccessClipCompleted;
decoder.Stop();
decoder.SetLooping(false);
decoder.OnPlayCompleted += OnSuccessClipCompleted;
int ret = decoder.PlayVideo(clip, decoder.AlphaType, multithreadedDecode: true);
if (ret != 0)
{
decoder.OnPlayCompleted -= OnSuccessClipCompleted;
PlayIdleInternal();
}
}
public override void PlayMatchReaction(bool isSuccessMore)
{
TextAsset clip = isSuccessMore ? successMoreVideo : successVideo;
if (decoder == null || clip == null)
{
PlayIdleInternal();
return;
}
// 已在播成功/大三消等非待机视频时,不打断、不重切
if (decoder.IsPlaying && idleVideo != null && decoder.bytesFile != null && decoder.bytesFile != idleVideo)
return;
decoder.OnPlayCompleted -= OnSuccessClipCompleted;
PlaySuccessClipInternal(clip);
}
void PlayIdleInternal()
{
if (decoder == null || idleVideo == null)
return;
decoder.Stop();
decoder.SetLooping(true);
decoder.PlayVideo(idleVideo, decoder.AlphaType, multithreadedDecode: true);
}
}