280 lines
8.5 KiB
C#
280 lines
8.5 KiB
C#
using Unity.VisualScripting;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class ServerWorkSceneController : MonoBehaviour
|
||
{
|
||
public static ServerWorkSceneController Instance;
|
||
|
||
public GameObject introPanel;
|
||
public GameObject messagePanel;
|
||
public GameObject messageReplyPanel;
|
||
public GameObject messageReplyWordsPanel;
|
||
public GameObject messageReplyWait1Panel;
|
||
public GameObject messageReplyWait1WorkingPanel;
|
||
public GameObject messageReplyWait2Panel;
|
||
public GameObject messageReplyWait2WorkingPanel;
|
||
public GameObject messageReplyExitPanel;
|
||
public GameObject messageReplyExitSurveyPanel;
|
||
public GameObject exitWorkPanel;
|
||
public GameObject messageReplyContinuePanel;
|
||
|
||
public GameObject gamePanel;
|
||
public GameObject gameTalkingPanel;
|
||
public GameObject gameTypingPanel;
|
||
public GameObject gameSticksPanel;
|
||
public GameObject gameWaittingPanel;
|
||
public GameObject gameFinalPanel;
|
||
public GameObject gameFinalSurveyPanel;
|
||
|
||
void Awake()
|
||
{
|
||
Instance = this;
|
||
}
|
||
private void OnEnable()
|
||
{
|
||
|
||
}
|
||
private void OnDisable()
|
||
{
|
||
Instance = null;
|
||
}
|
||
|
||
void Start()
|
||
{
|
||
SetupScene();
|
||
}
|
||
|
||
void SetupScene()
|
||
{
|
||
// ⭐ 關鍵修正 3:在場景啟動時檢查是否有緩存的願望訊息
|
||
if (NetworkMessageHandler.Instance != null && NetworkMessageHandler.Instance.hasPendingWorkMessage)
|
||
{
|
||
// 如果有緩存的訊息,直接進入 Step 2 (Message Panel)
|
||
Debug.Log("ServerWorkScene 載入完成,發現緩存願望訊息,直接跳到 Step 2。");
|
||
processStep(2);
|
||
|
||
// 【新增修正點 A】:強制在流程切換後,Panel 讀取最新的靜態資料
|
||
// 這可以確保 Panel 不會錯過資料。
|
||
if (ServerWorkMessagePanel.Instance != null)
|
||
{
|
||
ServerWorkMessagePanel.Instance.onReceivedData();
|
||
Debug.Log("強制呼叫 ServerWorkMessagePanel.onReceivedData() 來顯示願望內容。");
|
||
}
|
||
|
||
// 清除緩存旗標,防止下次場景重載誤判
|
||
NetworkMessageHandler.Instance.hasPendingWorkMessage = false;
|
||
}
|
||
else
|
||
{
|
||
// 正常流程:從 Step 1 (Intro Panel) 開始
|
||
Debug.Log("ServerWorkScene 正常載入,從 Step 1 (Intro Panel) 開始。");
|
||
processStep(1);
|
||
}
|
||
}
|
||
|
||
public void processStep(int step)
|
||
{
|
||
if (introPanel)
|
||
{
|
||
introPanel.SetActive(step == 1 ? true : false);
|
||
if (step == 1)
|
||
{
|
||
ServerWorkMessagePanel.workMessageCount = 0;
|
||
ServerWorkMessagePanel.workMessage = "";
|
||
ServerWorkMessagePanel.workMessageType = "";
|
||
ServerWorkMessagePanel.workPresent = "";
|
||
|
||
|
||
}
|
||
}
|
||
if (messagePanel)
|
||
{
|
||
messagePanel.SetActive(step == 2 ? true : false);
|
||
if (step == 2)
|
||
{
|
||
|
||
}
|
||
}
|
||
if (messageReplyPanel)
|
||
{
|
||
messageReplyPanel.SetActive(step == 3 ? true : false);
|
||
|
||
}
|
||
if (messageReplyWordsPanel)
|
||
{
|
||
messageReplyWordsPanel.SetActive(step == 4 ? true : false);
|
||
}
|
||
if (messageReplyWait1Panel)
|
||
{
|
||
messageReplyWait1Panel.SetActive(step == 5 ? true : false);
|
||
if (ServerWorkMessageReplyWait1Panel.Instance)
|
||
{
|
||
if (step == 5)
|
||
{
|
||
ServerWorkMessageReplyWait1Panel.Instance.play();
|
||
}
|
||
else
|
||
{
|
||
ServerWorkMessageReplyWait1Panel.Instance.stop();
|
||
}
|
||
}
|
||
}
|
||
if (messageReplyWait1WorkingPanel)
|
||
{
|
||
messageReplyWait1WorkingPanel.SetActive(step == 6 ? true : false);
|
||
if (ServerWorkMessageReplyWait1WorkingPanel.Instance)
|
||
{
|
||
if (step == 6)
|
||
{
|
||
ServerWorkMessageReplyWait1WorkingPanel.Instance.play();
|
||
}
|
||
else
|
||
{
|
||
ServerWorkMessageReplyWait1WorkingPanel.Instance.stop();
|
||
}
|
||
}
|
||
}
|
||
|
||
if (messageReplyWait2Panel)
|
||
{
|
||
messageReplyWait2Panel.SetActive(step == 7 ? true : false);
|
||
if (ServerWorkMessageReplyWait2Panel.Instance)
|
||
{
|
||
if (step == 7)
|
||
{
|
||
ServerWorkMessageReplyWait2Panel.Instance.play();
|
||
}
|
||
else
|
||
{
|
||
ServerWorkMessageReplyWait2Panel.Instance.stop();
|
||
}
|
||
}
|
||
}
|
||
if (messageReplyWait2WorkingPanel)
|
||
{
|
||
messageReplyWait2WorkingPanel.SetActive(step == 8 ? true : false);
|
||
if (ServerWorkMessageReplyWait2WorkingPanel.Instance)
|
||
{
|
||
if (step == 8)
|
||
{
|
||
ServerWorkMessageReplyWait2WorkingPanel.Instance.play();
|
||
}
|
||
else
|
||
{
|
||
ServerWorkMessageReplyWait2WorkingPanel.Instance.stop();
|
||
}
|
||
}
|
||
}
|
||
if (messageReplyExitPanel)
|
||
{
|
||
messageReplyExitPanel.SetActive(step == 9 ? true : false);
|
||
if (ServerWorkMessageReplyExitPanel.Instance)
|
||
{
|
||
if (step == 9)
|
||
{
|
||
ServerWorkMessageReplyExitPanel.Instance.play();
|
||
}
|
||
else
|
||
{
|
||
ServerWorkMessageReplyExitPanel.Instance.stop();
|
||
}
|
||
}
|
||
}
|
||
if (messageReplyExitSurveyPanel)
|
||
{
|
||
messageReplyExitSurveyPanel.SetActive(step == 10 ? true : false);
|
||
|
||
}
|
||
if (exitWorkPanel)
|
||
{
|
||
exitWorkPanel.SetActive(step == 11 ? true : false);
|
||
if (ServerWorkExitWorkPanel.Instance)
|
||
{
|
||
if (step == 11)
|
||
{
|
||
ServerWorkExitWorkPanel.Instance.play();
|
||
}
|
||
else
|
||
{
|
||
ServerWorkExitWorkPanel.Instance.stop();
|
||
}
|
||
}
|
||
}
|
||
if (messageReplyContinuePanel)
|
||
{
|
||
messageReplyContinuePanel.SetActive(step == 12 ? true : false);
|
||
if (ServerWorkMessageReplyContinuePanel.Instance)
|
||
{
|
||
if (step == 12)
|
||
{
|
||
ServerWorkMessageReplyContinuePanel.Instance.play();
|
||
}
|
||
else
|
||
{
|
||
ServerWorkMessageReplyContinuePanel.Instance.stop();
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
if (gamePanel)
|
||
{
|
||
gamePanel.SetActive(step == 13 ? true : false);
|
||
if (step == 13)
|
||
{
|
||
//ServerGamePanel.nameOfTheGameWillBeOpened = "";
|
||
}
|
||
}
|
||
if (gameTalkingPanel)
|
||
{
|
||
gameTalkingPanel.SetActive(step == 14 ? true : false);
|
||
if (step == 14)
|
||
{
|
||
if (ServerGameTalkingPanel.Instance)
|
||
{
|
||
ServerGameTalkingPanel.Instance.init();
|
||
}
|
||
}
|
||
|
||
}
|
||
if (gameTypingPanel)
|
||
{
|
||
gameTypingPanel.SetActive(step == 15 ? true : false);
|
||
if (step == 15)
|
||
{
|
||
if (ServerGameTypingPanel.Instance)
|
||
{
|
||
ServerGameTypingPanel.Instance.init();
|
||
}
|
||
}
|
||
}
|
||
if (gameSticksPanel)
|
||
{
|
||
gameSticksPanel.SetActive(step == 16 ? true : false);
|
||
}
|
||
if (gameWaittingPanel)
|
||
{
|
||
gameWaittingPanel.SetActive(step == 17 ? true : false);
|
||
}
|
||
if (gameFinalPanel)
|
||
{
|
||
gameFinalPanel.SetActive(step == 18 ? true : false);
|
||
if (ServerWorkGameFinalPanel.Instance)
|
||
{
|
||
ServerWorkGameFinalPanel.Instance.init();
|
||
}
|
||
}
|
||
if (gameFinalSurveyPanel)
|
||
{
|
||
gameFinalSurveyPanel.SetActive(step == 19 ? true : false);
|
||
}
|
||
}
|
||
// ServerWorkSceneController.cs 腳本中
|
||
public void GoToGameWaitingPanel()
|
||
{
|
||
// 呼叫核心流程方法,將步驟設定為 17
|
||
processStep(17);
|
||
Debug.Log("Confirmed Sticks. Switching to Step 17 (Game Waiting Panel).");
|
||
}
|
||
} |