231 lines
6.5 KiB
C#
231 lines
6.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using TMPro;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.Video;
|
|
|
|
public class ServerGameTalkingPanel : MonoBehaviour
|
|
{
|
|
public static ServerGameTalkingPanel Instance;
|
|
|
|
public GameObject introPanel;
|
|
public GameObject playPanel;
|
|
|
|
public VideoPlayer introVideoPlayer;
|
|
public RawImage introRawImage;
|
|
|
|
public TMP_InputField playInputField;
|
|
public TMP_Text playChatText;
|
|
public Button playSendButton;
|
|
public TMP_Text statusText;
|
|
|
|
public Button sample1Button;
|
|
public Button sample2Button;
|
|
public Button sample3Button;
|
|
public Button sample4Button;
|
|
public Button sample5Button;
|
|
|
|
private CustomerReportSystem customReportScript;
|
|
|
|
private int gameTimeCountdownSecVal = GlobalData.GAME_TALK_COUNTDOWN_TIME;
|
|
|
|
private string[] sampleTexts = {
|
|
"汝行街上,見一老嫗跌倒,身旁五千金鈔隨風散。若只得一瞬之舉,汝先救人,抑或先拾錢?",
|
|
"汝見一孩以假幣買食,攤主未覺。若揭穿,孩餓;若不言,誤教。汝何選?",
|
|
"友人誤將重物砸壞汝物,卻以為無人知曉。汝心明白真相,是當面直言,還是靜默讓他安?",
|
|
"汝於雨夜撞傷野貓,車無損,人未見。汝會停車查看,抑或遠去以免麻煩?",
|
|
"汝在工廠,知上司指示排放廢水入河,若揭發,恐遭解雇;若隱瞞,公司利潤倍增。汝何解?"
|
|
};
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
customReportScript = gameObject.GetComponentInChildren<CustomerReportSystem>(includeInactive: true);
|
|
}
|
|
|
|
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
|
void Start()
|
|
{
|
|
SetupIntroVideoPlayer();
|
|
|
|
if (playSendButton)
|
|
{
|
|
playSendButton.onClick.AddListener(playSendButton_onClick);
|
|
}
|
|
|
|
if (sample1Button)
|
|
{
|
|
sample1Button.onClick.AddListener(sample1Button_onClick);
|
|
}
|
|
if (sample2Button)
|
|
{
|
|
sample2Button.onClick.AddListener(sample2Button_onClick);
|
|
}
|
|
if (sample3Button)
|
|
{
|
|
sample3Button.onClick.AddListener(sample3Button_onClick);
|
|
}
|
|
if (sample4Button)
|
|
{
|
|
sample4Button.onClick.AddListener(sample4Button_onClick);
|
|
}
|
|
if (sample5Button)
|
|
{
|
|
sample5Button.onClick.AddListener(sample5Button_onClick);
|
|
}
|
|
|
|
customReportScript.OnCustomerReportConfirmed = OnCustomerReportConfirmed;
|
|
}
|
|
|
|
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 sample5Button_onClick()
|
|
{
|
|
playInputField.text = sampleTexts[4];
|
|
|
|
}
|
|
|
|
private void sample4Button_onClick()
|
|
{
|
|
playInputField.text = sampleTexts[3];
|
|
|
|
}
|
|
|
|
private void sample3Button_onClick()
|
|
{
|
|
playInputField.text = sampleTexts[2];
|
|
|
|
}
|
|
|
|
private void sample2Button_onClick()
|
|
{
|
|
playInputField.text = sampleTexts[1];
|
|
}
|
|
|
|
private void sample1Button_onClick()
|
|
{
|
|
playInputField.text = sampleTexts[0];
|
|
}
|
|
|
|
public void init()
|
|
{
|
|
processStep(1);
|
|
if (introVideoPlayer)
|
|
{
|
|
introVideoPlayer.Play();
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
public void onReceivedChatMessage(string message)
|
|
{
|
|
playChatText.text = "-信眾-<br>" + message + "<br>" + playChatText.text;
|
|
}
|
|
|
|
private void playSendButton_onClick()
|
|
{
|
|
if (playInputField.text.Length > 0)
|
|
{
|
|
if (NetworkMessageHandler.Instance)
|
|
{
|
|
NetworkMessageHandler.Instance.SendMessageToClient("gameTalkingGodSay", playInputField.text);
|
|
}
|
|
playChatText.text = "<align=\"right\"><color=#63584A>-神明-<br>" + playInputField.text + "</color></align><br>" + playChatText.text;
|
|
playInputField.text = "";
|
|
}
|
|
}
|
|
|
|
IEnumerator GameTimeCountdown()
|
|
{
|
|
yield return new WaitForSeconds(1f);
|
|
|
|
if (gameTimeCountdownSecVal == GlobalData.GAME_TALK_COUNTDOWN_TIME)
|
|
{
|
|
if (NetworkMessageHandler.Instance)
|
|
{
|
|
NetworkMessageHandler.Instance.SendMessageToClient("gameTalkingStart", "");
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void processStep(int step)
|
|
{
|
|
if (introPanel)
|
|
{
|
|
introPanel.SetActive(step == 1);
|
|
if (step == 1)
|
|
{
|
|
gameTimeCountdownSecVal = GlobalData.GAME_TALK_COUNTDOWN_TIME;
|
|
}
|
|
}
|
|
if (playPanel)
|
|
{
|
|
playPanel.SetActive(step == 2);
|
|
if (step == 2)
|
|
{
|
|
playChatText.text = "";
|
|
statusText.text = "倒計時 : <color=\"red\">" + gameTimeCountdownSecVal.ToString() + "</color>s";
|
|
StartCoroutine(GameTimeCountdown());
|
|
}
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|