46 lines
1.1 KiB
C#
46 lines
1.1 KiB
C#
|
using System;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.Video;
|
|||
|
|
|||
|
namespace UnityTest.ZXL
|
|||
|
{
|
|||
|
public class TimeReversalUI : UI
|
|||
|
{
|
|||
|
private VideoPlayer _videoPlayer;
|
|||
|
private Action _action;
|
|||
|
|
|||
|
public override void OnInit()
|
|||
|
{
|
|||
|
base.OnInit();
|
|||
|
_videoPlayer = GetComponentInChildren<VideoPlayer>();
|
|||
|
_videoPlayer.started += Started;
|
|||
|
_videoPlayer.loopPointReached += End;
|
|||
|
}
|
|||
|
|
|||
|
private void OnDestroy()
|
|||
|
{
|
|||
|
_videoPlayer.started -= Started;
|
|||
|
_videoPlayer.loopPointReached -= End;
|
|||
|
}
|
|||
|
|
|||
|
private void Started(VideoPlayer source)
|
|||
|
{
|
|||
|
Debug.Log("播放开始");
|
|||
|
// TODO: 关闭所有UI,待播放结束后开启被关闭的UI
|
|||
|
UIManager.Instance().HideAllUI();
|
|||
|
UIManager.Instance().ShowUI(UIType.TimeReversal);
|
|||
|
}
|
|||
|
|
|||
|
private void End(VideoPlayer source)
|
|||
|
{
|
|||
|
Debug.Log("播放结束");
|
|||
|
_action?.Invoke();
|
|||
|
}
|
|||
|
|
|||
|
public void SetAction(Action action)
|
|||
|
{
|
|||
|
_action = action;
|
|||
|
_videoPlayer.Play();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|