80 lines
1.7 KiB
C#
80 lines
1.7 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.Video;
|
|
|
|
public class ServerWorkExitWorkPanel : MonoBehaviour
|
|
{
|
|
public static ServerWorkExitWorkPanel Instance;
|
|
|
|
[Header("影片播放")]
|
|
public VideoPlayer videoPlayer;
|
|
public RawImage videoDisplay;
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
SetupVideoPlayer();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
public void play()
|
|
{
|
|
if (videoPlayer != null)
|
|
{
|
|
videoPlayer.Play();
|
|
}
|
|
}
|
|
|
|
public void stop()
|
|
{
|
|
if (videoPlayer != null)
|
|
{
|
|
videoPlayer.Stop();
|
|
}
|
|
}
|
|
|
|
void SetupVideoPlayer()
|
|
{
|
|
if (videoPlayer != null)
|
|
{
|
|
// 設置影片結束事件
|
|
videoPlayer.loopPointReached += OnVideoFinished;
|
|
|
|
// 設置影片顯示
|
|
if (videoDisplay != null)
|
|
{
|
|
videoPlayer.targetTexture = null;
|
|
videoPlayer.renderMode = VideoRenderMode.RenderTexture;
|
|
RenderTexture rt = new RenderTexture(1920, 1080, 24);
|
|
videoPlayer.targetTexture = rt;
|
|
videoDisplay.texture = rt;
|
|
}
|
|
}
|
|
}
|
|
|
|
void OnVideoFinished(VideoPlayer vp)
|
|
{
|
|
Debug.Log("影片播放完成");
|
|
StartCoroutine(LoadHomeScene());
|
|
}
|
|
|
|
IEnumerator LoadHomeScene()
|
|
{
|
|
yield return new WaitForSeconds(0f);
|
|
SceneManager.LoadScene("ServerHomeScene");
|
|
}
|
|
}
|