Petition-to-the-Gods-V3/Assets/Scripts/Server/ServerGameTypingPanel.cs
2025-11-18 07:48:42 +08:00

175 lines
4.2 KiB
C#
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
{
// ³]¸m¼v¤ùµ²§ô¨Æ¥ó
introVideoPlayer.loopPointReached += OnIntroVideoFinished;
// ³]¸m¼v¤ùÅã¥Ü
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("¼v¤ù¼½©ñ§¹¦¨");
//StartCoroutine(LoadNextScene());
processStep(2);
}
void SetupPlayVideoPlayer()
{
if (introVideoPlayer != null)
{
// ³]¸m¼v¤ùµ²§ô¨Æ¥ó
playVideoPlayer.loopPointReached += OnPlayVideoFinished;
// ³]¸m¼v¤ùÅã¥Ü
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("¼v¤ù¼½©ñ§¹¦¨");
//StartCoroutine(LoadNextScene());
OnReceivedResult();
}
public void OnReceivedResult()
{
if (!string.IsNullOrEmpty(result))
{
processStep(3);
}
}
IEnumerator GameTimeCountdown()
{
yield return new WaitForSeconds(1f);
gameTimeCountdownSecVal--;
statusText.text = "­Ë­p®É : <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();
}
private void checkOkButton_onClicked()
{
ServerWorkSceneController.Instance.processStep(17); // go to gameWaittingPanel
}
// Update is called once per frame
void Update()
{
}
}