LaboratoryProtection/Assets/UnityTest/ZXL/Scripts/UI/TimeReversalUI.cs

61 lines
1.6 KiB
C#
Raw Normal View History

2023-10-05 02:31:29 +08:00
using System;
using System.IO;
2023-10-05 13:49:55 +08:00
using Sirenix.OdinInspector;
2023-10-05 02:31:29 +08:00
using UnityEngine;
2023-10-08 17:04:32 +08:00
using UnityEngine.UI;
2023-10-05 02:31:29 +08:00
using UnityEngine.Video;
namespace UnityTest.ZXL
{
public class TimeReversalUI : UI
{
2023-10-05 13:49:55 +08:00
[SerializeField] private VideoPlayer _videoPlayer;
2023-10-05 02:31:29 +08:00
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 vp)
2023-10-05 02:31:29 +08:00
{
Debug.Log("播放开始");
// TODO: 关闭所有UI待播放结束后开启被关闭的UI
2023-10-05 14:29:32 +08:00
// UIManager.Instance().HideAllUI();
// UIManager.Instance().ShowUI(UIType.TimeReversal);
2023-10-08 17:04:32 +08:00
_videoPlayer.GetComponent<RawImage>().enabled = true;
2023-10-05 02:31:29 +08:00
}
private void End(VideoPlayer source)
{
Debug.Log("播放结束");
_action?.Invoke();
}
public void SetAction(Action action)
{
_action = action;
_videoPlayer.url = $"{Application.streamingAssetsPath}/TimeReversal.mp4";
_videoPlayer.Play();
2023-10-08 17:04:32 +08:00
_videoPlayer.GetComponent<RawImage>().enabled = false;
2023-10-05 13:49:55 +08:00
}
#if UNITY_EDITOR
[Button]
void Test()
{
_videoPlayer.url = $"{Application.streamingAssetsPath}/TimeReversal.mp4";
2023-10-05 02:31:29 +08:00
_videoPlayer.Play();
}
2023-10-05 13:49:55 +08:00
#endif
2023-10-05 02:31:29 +08:00
}
}