Petition-to-the-Gods-V3/Assets/Scripts/Server/ServerWorkGameFinalPanel.cs
2025-11-18 14:54:11 +08:00

203 lines
5.8 KiB
C#

using System;
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;
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;
}
}
else
{
}
}
if (replyPanel)
{
replyPanel.SetActive(step == 2);
}
if (waittingPanel)
{
waittingPanel.SetActive(step == 3);
if (waittingVideoPlayer)
{
waittingVideoPlayer.Play();
}
}
}
}