157 lines
3.9 KiB
C#
157 lines
3.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class ClientGameTalkingSceneController : MonoBehaviour
|
|
{
|
|
public static ClientGameTalkingSceneController Instance;
|
|
public static int playCount = 0;
|
|
|
|
public GameObject introPanel;
|
|
public GameObject playPanel;
|
|
public GameObject stopPanel;
|
|
public GameObject finishPanel;
|
|
|
|
public TMP_Text playCountdownText;
|
|
public TMP_Text playChatText;
|
|
public TMP_InputField playMessageInputField;
|
|
public Button playMessageSendButton;
|
|
|
|
public Button finishGoToNextButton;
|
|
public Button finishBackToMenuButton;
|
|
|
|
private int playCountdownSecVal = 120;
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
// 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);
|
|
}
|
|
if (playMessageSendButton)
|
|
{
|
|
playMessageSendButton.onClick.AddListener(playMessageSendButton_onClicked);
|
|
}
|
|
|
|
processStep(1);
|
|
}
|
|
|
|
private void playMessageSendButton_onClicked()
|
|
{
|
|
if (playMessageInputField.text.Length > 0)
|
|
{
|
|
if (ClientMessageHandler.Instance)
|
|
{
|
|
ClientMessageHandler.Instance.SendMessageToServer("gameTalkingPeopleSay", playMessageInputField.text);
|
|
}
|
|
|
|
playChatText.text = "<align=\"right\"><color=#63584A>-信眾-<br>" + playMessageInputField.text + "</color></align><br>" + playChatText.text;
|
|
playMessageInputField.text = "";
|
|
}
|
|
}
|
|
|
|
public void onReceivedChatMessage(string message)
|
|
{
|
|
|
|
playChatText.text = "-神明-<br>" + message + "<br>" + playChatText.text;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
private void finishGoToNextButton_onClicked()
|
|
{
|
|
|
|
if (ClientMessageHandler.Instance)
|
|
{
|
|
ClientMessageHandler.Instance.SendMessageToServer("getWords", "");
|
|
}
|
|
StartCoroutine(LoadNextScene("ClientGameBackToRealScene"));
|
|
}
|
|
|
|
private void finishBackToMenuButton_onClicked()
|
|
{
|
|
StartCoroutine(LoadNextScene("ClientGameScene"));
|
|
}
|
|
|
|
public void processStep(int step)
|
|
{
|
|
if (introPanel)
|
|
{
|
|
introPanel.SetActive( step == 1 );
|
|
if (step == 1)
|
|
{
|
|
playCount++;
|
|
playCountdownSecVal = 120;
|
|
}
|
|
|
|
}
|
|
if (playPanel)
|
|
{
|
|
playPanel.SetActive ( step == 2 );
|
|
if (step == 2)
|
|
{
|
|
StartCoroutine(StatusCountdown());
|
|
}
|
|
}
|
|
if (stopPanel)
|
|
{
|
|
stopPanel.SetActive ( step == 3 );
|
|
if (step == 3)
|
|
{
|
|
StartCoroutine(NextStep(4, 3));
|
|
}
|
|
}
|
|
if (finishPanel)
|
|
{
|
|
finishPanel.SetActive ( step == 4 );
|
|
}
|
|
}
|
|
|
|
IEnumerator LoadNextScene(string sceneName)
|
|
{
|
|
yield return new WaitForSeconds(0f);
|
|
SceneManager.LoadScene(sceneName);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|