193 lines
5.1 KiB
C#
193 lines
5.1 KiB
C#
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 CustomerReportSystem customReportScript;
|
|
|
|
private int gameTimeCountdownSecVal = 10;
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
customReportScript = gameObject.GetComponentInChildren<CustomerReportSystem>(includeInactive: true);
|
|
}
|
|
|
|
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("影片播放完成");
|
|
processStep(3); // ✅ 直接跳到 CheckPanel,不管result有沒有收到
|
|
}
|
|
|
|
public void OnReceivedResult()
|
|
{
|
|
// 這個方法改成:當收到result時才更新顯示文字
|
|
if (!string.IsNullOrEmpty(result))
|
|
{
|
|
checkText.text = result; // ✅ 更新顯示信徒打的字
|
|
}
|
|
}
|
|
|
|
IEnumerator GameTimeCountdown()
|
|
{
|
|
yield return new WaitForSeconds(1f);
|
|
|
|
|
|
|
|
gameTimeCountdownSecVal--;
|
|
statusText.text = "倒計時 : <color=\"red\">" + gameTimeCountdownSecVal.ToString() + "</color>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();
|
|
|
|
customReportScript.OnCustomerReportConfirmed = OnCustomerReportConfirmed;
|
|
|
|
init();
|
|
}
|
|
public void init()
|
|
{
|
|
processStep(1);
|
|
}
|
|
private void OnCustomerReportConfirmed(int[] values)
|
|
{
|
|
if (values.Length < 3) { return; }
|
|
if (ServerWorkTopRightScore.Instance == null) { return; }
|
|
|
|
GlobalData.VIRTUE_SCORE = values[0];
|
|
GlobalData.KARMA_SCORE = values[1];
|
|
GlobalData.SINCERITY_SCORE = values[2];
|
|
ServerWorkTopRightScore.Instance.UpdateScoreVals();
|
|
}
|
|
|
|
private void checkOkButton_onClicked()
|
|
{
|
|
ServerWorkSceneController.Instance.processStep(17); // go to gameWaittingPanel
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|