129 lines
3.5 KiB
C#
129 lines
3.5 KiB
C#
using System;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class ServerWorkMessagePanel : MonoBehaviour
|
||
{
|
||
public static ServerWorkMessagePanel Instance;
|
||
public static string workMessageType = "";
|
||
public static string workMessage = "";
|
||
public static string workPresent = "";
|
||
public static int workMessageCount = 0;
|
||
|
||
[Header("UI 元件")]
|
||
public GameObject messageLoadPanel;
|
||
public GameObject messageReceivedPanel;
|
||
public TMP_Text messageInfoText;
|
||
public TMP_Text typeText;
|
||
public TMP_Text messageText;
|
||
public TMP_Text presentText;
|
||
public Button replyButton;
|
||
|
||
public static void cleanData()
|
||
{
|
||
//workMessageType = "";
|
||
//workMessage = "";
|
||
//workPresent = "";
|
||
}
|
||
|
||
private void Awake()
|
||
{
|
||
Instance = this;
|
||
}
|
||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||
void Start()
|
||
{
|
||
if (messageLoadPanel)
|
||
{
|
||
messageLoadPanel.SetActive(false);
|
||
}
|
||
if (messageReceivedPanel)
|
||
{
|
||
messageReceivedPanel.SetActive(false);
|
||
}
|
||
if (replyButton)
|
||
{
|
||
replyButton.onClick.AddListener(replyButton_onClicked);
|
||
}
|
||
//onReceivedData();
|
||
}
|
||
private void OnEnable()
|
||
{
|
||
// 如果 Panel 被啟用時,數據已經在 NetworkMessageHandler 設置完成,
|
||
// 這裡會立即執行 onReceivedData 刷新狀態。
|
||
//onReceivedData();
|
||
}
|
||
|
||
public void onReceivedData()
|
||
{
|
||
if (string.IsNullOrEmpty(workMessageType)) // 如果靜態數據為空
|
||
{
|
||
if (messageLoadPanel)
|
||
{
|
||
messageLoadPanel.SetActive(true);
|
||
}
|
||
if (messageInfoText)
|
||
{
|
||
messageInfoText.text = "系統提示:請稍後,連接客戶的願望中...";
|
||
}
|
||
return;
|
||
}
|
||
// 如果 workMessageType 不為空,表示數據已收到,將顯示 messageReceivedPanel
|
||
if (messageInfoText)
|
||
{
|
||
messageInfoText.text = "系統提示:客戶已傳達願望給您,是否要幫助此客戶?請點擊回覆";
|
||
}
|
||
if (messageLoadPanel)
|
||
{
|
||
messageLoadPanel.SetActive(false);
|
||
}
|
||
if (messageReceivedPanel)
|
||
{
|
||
messageReceivedPanel.SetActive(true);
|
||
}
|
||
if (typeText)
|
||
{
|
||
switch(workMessageType)
|
||
{
|
||
case "TypeMoneyButton":
|
||
typeText.text = "財運";
|
||
break;
|
||
case "TypeHealthButton":
|
||
typeText.text = "健康";
|
||
break;
|
||
case "TypeLoveButton":
|
||
typeText.text = "愛情";
|
||
break;
|
||
default: // "TypeWorkButton"
|
||
typeText.text = "工作";
|
||
break;
|
||
}
|
||
|
||
}
|
||
if (messageText)
|
||
{
|
||
messageText.text = workMessage;
|
||
}
|
||
if (presentText)
|
||
{
|
||
presentText.text = "獻上:" + workPresent;
|
||
}
|
||
}
|
||
|
||
private void replyButton_onClicked()
|
||
{
|
||
//this.gameObject.SetActive(false);
|
||
if (ServerWorkSceneController.Instance != null)
|
||
{
|
||
ServerWorkSceneController.Instance.processStep(3);
|
||
}
|
||
}
|
||
|
||
// Update is called once per frame
|
||
void Update()
|
||
{
|
||
|
||
}
|
||
}
|