From 1fe6a922101308e49278092ada845de767b01cd4 Mon Sep 17 00:00:00 2001 From: qup35p <0528angelina@gmail.com> Date: Wed, 19 Nov 2025 21:07:17 +0800 Subject: [PATCH] =?UTF-8?q?<=E8=A7=A3=E6=B1=BAQ30>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ClientGameBackToRealSceneController.cs | 44 ++++++++++++++++--- Assets/Scripts/Client/ClientMessageHandler.cs | 7 +-- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/Assets/Scripts/Client/ClientGameBackToRealSceneController.cs b/Assets/Scripts/Client/ClientGameBackToRealSceneController.cs index d01a95e..8a0adce 100644 --- a/Assets/Scripts/Client/ClientGameBackToRealSceneController.cs +++ b/Assets/Scripts/Client/ClientGameBackToRealSceneController.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; @@ -11,6 +11,10 @@ public class ClientGameBackToRealSceneController : MonoBehaviour public VideoPlayer videoPlayer; public RawImage videoDisplay; + // --- 【新增變數】用於追蹤兩個條件是否滿足 --- + private bool isVideoFinished = false; + private bool isSignalReceived = false; + private void Awake() { Instance = this; @@ -35,7 +39,7 @@ public class ClientGameBackToRealSceneController : MonoBehaviour // 設置影片結束事件 videoPlayer.loopPointReached += OnVideoFinished; - // 設置影片顯示 + // 設置影片顯示 (略) if (videoDisplay != null) { videoPlayer.targetTexture = null; @@ -47,13 +51,43 @@ public class ClientGameBackToRealSceneController : MonoBehaviour } } + // 影片播放結束時呼叫 void OnVideoFinished(VideoPlayer vp) { - Debug.Log("影片播放完成,準備跳轉"); - if (!string.IsNullOrEmpty(ClientLastWordsSceneController.words)) + Debug.Log("影片播放完成。"); + isVideoFinished = true; // 影片結束標記設為 true + CheckAndLoadScene(); // 檢查是否可以跳轉 + } + + // --- 【新增方法】供 ClientMessageHandler 呼叫,標記訊號已收到 --- + public void ReceiveSignalFromPlayerB() + { + Debug.Log("收到玩家B的訊號 (gameFinalWords)。"); + isSignalReceived = true; // 訊號接收標記設為 true + CheckAndLoadScene(); // 檢查是否可以跳轉 + } + + // --- 【新增方法】核心檢查跳轉邏輯 --- + private void CheckAndLoadScene() + { + // 確保 ClientLastWordsSceneController.words 已經有值 + bool hasWords = !string.IsNullOrEmpty(ClientLastWordsSceneController.words); + + if (isVideoFinished && isSignalReceived && hasWords) { + Debug.Log("🎉 影片和訊號條件滿足,準備跳轉到下一場景..."); StartCoroutine(LoadNextScene()); } + else if (isVideoFinished && !isSignalReceived) + { + // 影片已結束,等待訊號 + Debug.Log("影片已結束,正在等待玩家B訊號..."); + } + else if (!isVideoFinished && isSignalReceived) + { + // 訊號已收到,等待影片結束 + Debug.Log("已收到玩家B訊號,正在等待影片播放完成..."); + } } public IEnumerator LoadNextScene() @@ -61,4 +95,4 @@ public class ClientGameBackToRealSceneController : MonoBehaviour yield return new WaitForSeconds(0f); SceneManager.LoadScene("ClientLastWordsScene"); } -} +} \ No newline at end of file diff --git a/Assets/Scripts/Client/ClientMessageHandler.cs b/Assets/Scripts/Client/ClientMessageHandler.cs index 34065e6..2de2e9b 100644 --- a/Assets/Scripts/Client/ClientMessageHandler.cs +++ b/Assets/Scripts/Client/ClientMessageHandler.cs @@ -1,4 +1,4 @@ -using UnityEngine; +using UnityEngine; using Mirror; using System; @@ -81,10 +81,11 @@ public class ClientMessageHandler : MonoBehaviour ClientLastWordsSceneController.words = msg.payload; if (ClientGameBackToRealSceneController.Instance) { - StartCoroutine( ClientGameBackToRealSceneController.Instance.LoadNextScene()); +                                // ✅ 將直接跳轉的程式碼,改為呼叫新的檢查函式 +                                ClientGameBackToRealSceneController.Instance.ReceiveSignalFromPlayerB(); } } - + } break; case "gameTalkingStart":