using System; using System.Collections; using TMPro; using UnityEngine; using UnityEngine.UI; using UnityEngine.Video; public class ServerGameTypingPanel : MonoBehaviour { public static ServerGameTypingPanel Instance; public static string result; public GameObject introPanel; public GameObject playPanel; public GameObject checkPanel; public VideoPlayer introVideoPlayer; public RawImage introRawImage; public VideoPlayer playVideoPlayer; public RawImage playRawImage; public TMP_Text statusText; public TMP_Text checkText; public Button checkOkButton; private int gameTimeCountdownSecVal = 10; private void Awake() { Instance = this; } public void processStep(int step) { if (introPanel) { introPanel.SetActive(step == 1); if (step == 1) { gameTimeCountdownSecVal = 10; if (introVideoPlayer) { introVideoPlayer.Play(); } } } if (playPanel) { playPanel.SetActive(step == 2); if (step == 2) { if (playVideoPlayer) { playVideoPlayer.Play(); } } } if (checkPanel) { checkPanel.SetActive(step == 3); if (step == 3) { checkText.text = result; StartCoroutine(GameTimeCountdown()); } } } void SetupIntroVideoPlayer() { if (introVideoPlayer != null) { // 設置影片結束事件 introVideoPlayer.loopPointReached += OnIntroVideoFinished; // 設置影片顯示 if (introVideoPlayer != null) { introVideoPlayer.targetTexture = null; introVideoPlayer.renderMode = VideoRenderMode.RenderTexture; RenderTexture rt = new RenderTexture(1920, 1080, 24); introVideoPlayer.targetTexture = rt; introRawImage.texture = rt; } } } void OnIntroVideoFinished(VideoPlayer vp) { Debug.Log("影片播放完成"); //StartCoroutine(LoadNextScene()); processStep(2); } void SetupPlayVideoPlayer() { if (introVideoPlayer != null) { // 設置影片結束事件 playVideoPlayer.loopPointReached += OnPlayVideoFinished; // 設置影片顯示 if (playVideoPlayer != null) { playVideoPlayer.targetTexture = null; playVideoPlayer.renderMode = VideoRenderMode.RenderTexture; RenderTexture rt = new RenderTexture(1920, 1080, 24); playVideoPlayer.targetTexture = rt; playRawImage.texture = rt; } } } void OnPlayVideoFinished(VideoPlayer vp) { Debug.Log("影片播放完成"); //StartCoroutine(LoadNextScene()); OnReceivedResult(); } public void OnReceivedResult() { if (!string.IsNullOrEmpty(result)) { processStep(3); } } IEnumerator GameTimeCountdown() { yield return new WaitForSeconds(1f); gameTimeCountdownSecVal--; statusText.text = "倒計時 : " + gameTimeCountdownSecVal.ToString() + "s"; if (gameTimeCountdownSecVal > 0) { StartCoroutine(GameTimeCountdown()); } else { if (ServerWorkSceneController.Instance) { ServerWorkSceneController.Instance.processStep(17); // go to gameWaittingPanel } } } // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { checkOkButton.onClick.AddListener(checkOkButton_onClicked); SetupIntroVideoPlayer(); SetupPlayVideoPlayer(); } private void checkOkButton_onClicked() { ServerWorkSceneController.Instance.processStep(17); // go to gameWaittingPanel } // Update is called once per frame void Update() { } }