79 lines
1.9 KiB
C#
79 lines
1.9 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.Video;
|
|
|
|
public class ServerWorkMessageReplyWait1WorkingPanel : MonoBehaviour
|
|
{
|
|
public static ServerWorkMessageReplyWait1WorkingPanel Instance;
|
|
|
|
[Header("影片播放")]
|
|
public VideoPlayer videoPlayer;
|
|
public RawImage videoDisplay;
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
public void StopWaitingAndGoToMessagePanel()
|
|
{
|
|
// 立即停止所有動畫或協程 (如果有的話)
|
|
// StopAllCoroutines();
|
|
// ...
|
|
|
|
// 強制切換到 Step 2
|
|
if (ServerWorkSceneController.Instance != null)
|
|
{
|
|
Debug.Log("ServerWorkMessageReplyWait1WorkingPanel: 收到新願望訊號,強制切換到 Step 2。");
|
|
ServerWorkSceneController.Instance.processStep(2);
|
|
}
|
|
}
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
SetupVideoPlayer();
|
|
|
|
}
|
|
|
|
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;
|
|
videoPlayer.isLooping = true;
|
|
videoDisplay.texture = rt;
|
|
}
|
|
}
|
|
}
|
|
|
|
void OnVideoFinished(VideoPlayer vp)
|
|
{
|
|
//Debug.Log("影片播放完成");
|
|
|
|
}
|
|
}
|