139 lines
3.2 KiB
C#
139 lines
3.2 KiB
C#
using System.Collections;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class ClientGameTypingSceneController : MonoBehaviour
|
|
{
|
|
public static ClientGameTypingSceneController Instance;
|
|
|
|
public GameObject introPanel;
|
|
public GameObject playPanel;
|
|
public GameObject stopPanel;
|
|
public GameObject finishPanel;
|
|
|
|
public TMP_Text playCountdownText;
|
|
public TMP_InputField playInputField;
|
|
|
|
public Button finishGoToNextButton;
|
|
public Button finishBackToMenuButton;
|
|
|
|
private int playCountdownSecVal = 60;
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
public void init()
|
|
{
|
|
processStep(1);
|
|
}
|
|
|
|
|
|
|
|
IEnumerator StatusCountdown()
|
|
{
|
|
yield return new WaitForSeconds(1f);
|
|
|
|
playCountdownSecVal--;
|
|
|
|
playCountdownText.text = "時間倒數 " + playCountdownSecVal.ToString() + "秒";
|
|
|
|
if (playCountdownSecVal > 0)
|
|
{
|
|
StartCoroutine(StatusCountdown());
|
|
}
|
|
else
|
|
{
|
|
processStep(3);
|
|
}
|
|
|
|
}
|
|
|
|
IEnumerator NextStep(int step, int waitSec)
|
|
{
|
|
yield return new WaitForSeconds(waitSec);
|
|
processStep(step);
|
|
}
|
|
|
|
|
|
public void processStep(int step)
|
|
{
|
|
if (introPanel)
|
|
{
|
|
introPanel.SetActive(step == 1);
|
|
if (step == 1)
|
|
{
|
|
playCountdownSecVal = 60;
|
|
StartCoroutine(NextStep(2, 3));
|
|
}
|
|
}
|
|
if (playPanel)
|
|
{
|
|
playPanel.SetActive(step == 2);
|
|
if (step == 2)
|
|
{
|
|
StartCoroutine(StatusCountdown());
|
|
}
|
|
}
|
|
if (stopPanel)
|
|
{
|
|
stopPanel.SetActive(step == 3);
|
|
if (step == 3)
|
|
{
|
|
if (ClientMessageHandler.Instance)
|
|
{
|
|
ClientMessageHandler.Instance.SendMessageToServer("gameTypingResult", playInputField.text);
|
|
}
|
|
StartCoroutine(NextStep(4, 3));
|
|
}
|
|
}
|
|
if (finishPanel)
|
|
{
|
|
finishPanel.SetActive(step == 4);
|
|
}
|
|
}
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
if (finishGoToNextButton)
|
|
{
|
|
finishGoToNextButton.onClick.AddListener(finishGoToNextButton_onClicked);
|
|
}
|
|
if (finishBackToMenuButton)
|
|
{
|
|
finishBackToMenuButton.onClick.AddListener(finishBackToMenuButton_onClicked);
|
|
}
|
|
init();
|
|
}
|
|
private void finishGoToNextButton_onClicked()
|
|
{
|
|
|
|
if (ClientMessageHandler.Instance)
|
|
{
|
|
ClientMessageHandler.Instance.SendMessageToServer("getWords", "");
|
|
}
|
|
StartCoroutine(LoadNextScene("ClientGameBackToRealScene"));
|
|
}
|
|
|
|
private void finishBackToMenuButton_onClicked()
|
|
{
|
|
StartCoroutine(LoadNextScene("ClientGameScene"));
|
|
}
|
|
|
|
IEnumerator LoadNextScene(string sceneName)
|
|
{
|
|
yield return new WaitForSeconds(0f);
|
|
SceneManager.LoadScene(sceneName);
|
|
}
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|