using System; using System.Collections; using TMPro; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI; using UnityEngine.Video; public class ServerWorkGameFinalPanel : MonoBehaviour { public static ServerWorkGameFinalPanel Instance; private int currentSampleWordsIndex = 0; private string[] sampleWords = { "福在心間非遠方行誠一步百事昌天開一線容人渡前路微光漸放芒", "命裡有時終必至急行反失遠行期靜看潮起潮又落好風自會送舟歸", "心誠萬事皆能順莫急莫慌自有門天道酬勤終不負善念長存歸本根", "汝問蒼天天不語早知汝路自難移命數原非神可改徒然叩首費心思", "求財無財空添亂問愛無愛更心煩問命問天徒自苦不如回家補個眠" }; public GameObject introPanel; public GameObject replyPanel; public GameObject waittingPanel; public Button introReplyButton; public TMP_Text introMessageTypeText; public TMP_Text introMessageText; public TMP_Text introPresentText; public Button wordsSubmitButton; public Button wordsLeftButton; public Button wordsRightButton; public TMP_InputField wordsInputField; public TMP_Text wordsMessageTypeText; public TMP_Text wordsMessageText; public TMP_Text wordsPresentText; public VideoPlayer waittingVideoPlayer; public RawImage waittingRawImage; public TMP_Text countdownText; public int wordsCountdownTime = GlobalData.WORD_COUNTDOWN_TIME; private void Awake() { Instance = this; } // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { if (introReplyButton) { introReplyButton.onClick.AddListener(introReplyButton_onClicked); } if (wordsLeftButton) { wordsLeftButton.onClick.AddListener(wordsLeftButton_onClicked); } if (wordsRightButton) { wordsRightButton.onClick.AddListener(wordsRightButton_onClicked); } if (wordsSubmitButton) { wordsSubmitButton.onClick.AddListener(wordsSubmitButton_onClicked); } SetupIntroVideoPlayer(); //init(); } void SetupIntroVideoPlayer() { if (waittingVideoPlayer != null) { // 設置影片結束事件 waittingVideoPlayer.loopPointReached += OnIntroVideoFinished; // 設置影片顯示 if (waittingVideoPlayer != null) { waittingVideoPlayer.isLooping = true; waittingVideoPlayer.targetTexture = null; waittingVideoPlayer.renderMode = VideoRenderMode.RenderTexture; RenderTexture rt = new RenderTexture(1920, 1080, 24); waittingVideoPlayer.targetTexture = rt; waittingRawImage.texture = rt; } } } void OnIntroVideoFinished(VideoPlayer vp) { //Debug.Log("影片播放完成"); //StartCoroutine(LoadNextScene()); } private void wordsSubmitButton_onClicked() { if (string.IsNullOrEmpty(wordsInputField.text)) { wordsInputField.text = sampleWords[0]; } NetworkMessageHandler.Instance.SendMessageToClient("gameFinalWords", wordsInputField.text); processStep(3); } private void wordsRightButton_onClicked() { if (wordsInputField) { currentSampleWordsIndex++; if (currentSampleWordsIndex >= sampleWords.Length) currentSampleWordsIndex = sampleWords.Length - 1; wordsInputField.text = sampleWords[currentSampleWordsIndex]; } } private void wordsLeftButton_onClicked() { if (wordsInputField) { currentSampleWordsIndex--; if (currentSampleWordsIndex < 0) currentSampleWordsIndex = 0; wordsInputField.text = sampleWords[currentSampleWordsIndex]; } } private void introReplyButton_onClicked() { processStep(2); } public void init() { processStep(1); } // Update is called once per frame void Update() { } public void processStep(int step) { if (introPanel) { introPanel.SetActive(step == 1); if (step == 1) { if (introMessageTypeText) { switch (ServerWorkMessagePanel.workMessageType) { case "TypeMoneyButton": introMessageTypeText.text = "財運"; break; case "TypeHealthButton": introMessageTypeText.text = "健康"; break; case "TypeLoveButton": introMessageTypeText.text = "愛情"; break; default: // "TypeWorkButton" introMessageTypeText.text = "工作"; break; } } if (introMessageText) { introMessageText.text = ServerWorkMessagePanel.workMessage; } if (introPresentText) { introPresentText.text = "獻上:" + ServerWorkMessagePanel.workPresent; } //更新word系列文字 if (wordsMessageTypeText) { wordsMessageTypeText.text = introMessageTypeText?.text ?? ""; } if (wordsMessageText) { wordsMessageText.text = introMessageText?.text ?? ""; } if (wordsPresentText) { wordsPresentText.text = "獻上:" + ServerWorkMessagePanel.workPresent; } } else { } } if (replyPanel) { replyPanel.SetActive(step == 2); //倒數時間 if (step == 2) { wordsCountdownTime = GlobalData.WORD_COUNTDOWN_TIME; UpdateWordsCountdownText(); StartCoroutine(WordCountdown()); } } if (waittingPanel) { waittingPanel.SetActive(step == 3); if (waittingVideoPlayer) { waittingVideoPlayer.Play(); } } } IEnumerator WordCountdown() { yield return new WaitForSeconds(1f); wordsCountdownTime--; UpdateWordsCountdownText(); if (wordsCountdownTime > 0) { StartCoroutine(WordCountdown()); } else { wordsSubmitButton_onClicked(); } } private void UpdateWordsCountdownText() { countdownText.text = "倒計時 : " + wordsCountdownTime.ToString() + "s"; } }