From 7e8fa7732a1614492b8ed1e234c4e807913b3d08 Mon Sep 17 00:00:00 2001 From: chiyulin0314 Date: Thu, 20 Nov 2025 07:30:00 +0800 Subject: [PATCH] =?UTF-8?q?fix=20Q25=20=E9=81=8A=E6=88=B23=E7=9A=84?= =?UTF-8?q?=E8=A7=92=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scripts/IncenseController.cs | 9 +++++++ .../ExportStick/Scripts/Incensegamemanager.cs | 17 +++++++++++- .../Scenes/Client/ClientGameSticksScene.unity | 12 +++++++++ Assets/Scenes/Server/ServerWorkScene.unity | 6 ++--- .../Client/ClientGameSticksSceneController.cs | 18 ++++++++++++- Assets/Scripts/MessageFmt.cs | 4 +++ .../Scripts/Server/NetworkMessageHandler.cs | 10 ++++++- .../Scripts/Server/ServerGameSticksPanel.cs | 26 ++++++++++++++++++- 8 files changed, 95 insertions(+), 7 deletions(-) diff --git a/Assets/ExporrtClientStickPrefab/Scripts/IncenseController.cs b/Assets/ExporrtClientStickPrefab/Scripts/IncenseController.cs index 4daa19a..d1216b8 100644 --- a/Assets/ExporrtClientStickPrefab/Scripts/IncenseController.cs +++ b/Assets/ExporrtClientStickPrefab/Scripts/IncenseController.cs @@ -43,6 +43,8 @@ public class IncenseController : MonoBehaviour private float fallTimer = 0f; private bool hasLanded = false; private float finalSincerity = 0f; + + public System.Action OnCountdownFinished; void Start() { @@ -81,6 +83,13 @@ public class IncenseController : MonoBehaviour CalculateStability(); UpdateVisuals(); UpdateUI(); + + // 觸發時間到事件 + if (hasLanded) + { + int angle = Mathf.RoundToInt(currentAngle); + OnCountdownFinished?.Invoke(angle); + } } else { diff --git a/Assets/ExportStick/Scripts/Incensegamemanager.cs b/Assets/ExportStick/Scripts/Incensegamemanager.cs index 7935b96..a3ad8bd 100644 --- a/Assets/ExportStick/Scripts/Incensegamemanager.cs +++ b/Assets/ExportStick/Scripts/Incensegamemanager.cs @@ -32,7 +32,7 @@ public class IncenseGameManager : MonoBehaviour public int gameOverCountdownSec = 10; // ✅ 新增:GameOver倒計時秒數 [Header("Result Settings")] - public float receivedAngle = 87.5f; // 假的接收角度,之後會從另一台電腦接收 + public float receivedAngle = 90f; // 假的接收角度,之後會從另一台電腦接收 [Header("Incense Settings")] public GameObject incensePrefab; @@ -46,6 +46,9 @@ public class IncenseGameManager : MonoBehaviour private int totalIncenseCount = 20; private bool gameActive = true; private int gameOverCountdownVal; // ✅ 新增:當前倒計時數值 + private bool isReceivedAngle = false; + + public System.Action OnCountdownFinished; void OnEnable() { @@ -57,6 +60,8 @@ public class IncenseGameManager : MonoBehaviour currentTime = gameTime; currentPowerValue = initialPowerValue; gameActive = true; + receivedAngle = 90f; + isReceivedAngle = false; // 顯示遊戲UI,隱藏結果UI if (gamePlayUI) gamePlayUI.SetActive(true); @@ -344,6 +349,9 @@ public class IncenseGameManager : MonoBehaviour // SceneManager.LoadScene("NextScene"); // 或者呼叫其他控制器的方法 Debug.Log("GameOver倒計時結束!"); + + // 觸發時間到事件 + OnCountdownFinished?.Invoke(); } void ClearAllIncense() @@ -361,6 +369,12 @@ public class IncenseGameManager : MonoBehaviour void SetupResultIncense() { + if (isReceivedAngle == false) + { + angleDisplayText.text = ""; + return; + } + if (resultIncense != null) { // 設置結果香的角度 @@ -383,6 +397,7 @@ public class IncenseGameManager : MonoBehaviour public void SetReceivedAngle(float angle) { receivedAngle = angle; + isReceivedAngle = true; if (!gameActive) // 如果已在結果畫面,立即更新 { SetupResultIncense(); diff --git a/Assets/Scenes/Client/ClientGameSticksScene.unity b/Assets/Scenes/Client/ClientGameSticksScene.unity index 628921a..dde6a8a 100644 --- a/Assets/Scenes/Client/ClientGameSticksScene.unity +++ b/Assets/Scenes/Client/ClientGameSticksScene.unity @@ -950,6 +950,7 @@ MonoBehaviour: playCountdownText: {fileID: 981401567} incenseTransform: {fileID: 1100068051} incenseHolderTransform: {fileID: 0} + incenseController: {fileID: 1726446969} finishGoToNextButton: {fileID: 535960335} finishBackToMenuButton: {fileID: 443005029} --- !u!114 &981401567 stripped @@ -1669,6 +1670,17 @@ PrefabInstance: m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: cefaaa3e8d6afa74d9be9cc1341b1a09, type: 3} +--- !u!114 &1726446969 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 6134439403010925337, guid: cefaaa3e8d6afa74d9be9cc1341b1a09, type: 3} + m_PrefabInstance: {fileID: 1726446968} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 571e1448f855fad41b25c97b16854985, type: 3} + m_Name: + m_EditorClassIdentifier: Assembly-CSharp::IncenseController --- !u!1 &1780727869 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/Server/ServerWorkScene.unity b/Assets/Scenes/Server/ServerWorkScene.unity index db168e0..9307d2f 100644 --- a/Assets/Scenes/Server/ServerWorkScene.unity +++ b/Assets/Scenes/Server/ServerWorkScene.unity @@ -2109,7 +2109,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &85247803 RectTransform: m_ObjectHideFlags: 0 @@ -9307,7 +9307,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 5304771535841513772, guid: 8c3e8d5430f6ce145b97407a9411b8a2, type: 3} propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.size - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 5304771535841513772, guid: 8c3e8d5430f6ce145b97407a9411b8a2, type: 3} propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_Mode @@ -9323,7 +9323,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 5304771535841513772, guid: 8c3e8d5430f6ce145b97407a9411b8a2, type: 3} propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_MethodName - value: GoToGameWaitingPanel + value: objectReference: {fileID: 0} - target: {fileID: 5304771535841513772, guid: 8c3e8d5430f6ce145b97407a9411b8a2, type: 3} propertyPath: m_OnClick.m_PersistentCalls.m_Calls.Array.data[0].m_TargetAssemblyTypeName diff --git a/Assets/Scripts/Client/ClientGameSticksSceneController.cs b/Assets/Scripts/Client/ClientGameSticksSceneController.cs index f987314..c4a25c0 100644 --- a/Assets/Scripts/Client/ClientGameSticksSceneController.cs +++ b/Assets/Scripts/Client/ClientGameSticksSceneController.cs @@ -17,6 +17,7 @@ public class ClientGameSticksSceneController : MonoBehaviour public TMP_Text playCountdownText; public Transform incenseTransform; public Transform incenseHolderTransform; + public IncenseController incenseController; private Image sincerityMeterFill; @@ -106,7 +107,7 @@ public class ClientGameSticksSceneController : MonoBehaviour { ClientMessageHandler.Instance.SendMessageToServer("gameSticksFinish", ""); } - StartCoroutine(NextStep(4, 3)); + StartCoroutine(NextStep(4, 6)); } } if (finishPanel) @@ -129,7 +130,22 @@ public class ClientGameSticksSceneController : MonoBehaviour } init(); + incenseController.OnCountdownFinished = OnCountdownFinished; } + + private void OnCountdownFinished(int angle) + { + if (ClientMessageHandler.Instance) + { + GameSticksResult msgObj = new GameSticksResult { + angle = angle, + }; + + string payload = JsonUtility.ToJson(msgObj); + ClientMessageHandler.Instance.SendMessageToServer("gameSticksFinish", payload); + } + } + private void finishGoToNextButton_onClicked() { diff --git a/Assets/Scripts/MessageFmt.cs b/Assets/Scripts/MessageFmt.cs index d86a60d..759ac7b 100644 --- a/Assets/Scripts/MessageFmt.cs +++ b/Assets/Scripts/MessageFmt.cs @@ -37,3 +37,7 @@ public class GameMessageSurvey public string text1; } +public class GameSticksResult +{ + public int angle; +} \ No newline at end of file diff --git a/Assets/Scripts/Server/NetworkMessageHandler.cs b/Assets/Scripts/Server/NetworkMessageHandler.cs index de09fb4..1662c1d 100644 --- a/Assets/Scripts/Server/NetworkMessageHandler.cs +++ b/Assets/Scripts/Server/NetworkMessageHandler.cs @@ -230,7 +230,15 @@ public class NetworkMessageHandler : MonoBehaviour break; case "gameSticksFinish": { - // 保持不變 + GameSticksResult msgObj = JsonUtility.FromJson(msg.payload); + + if (msgObj != null) + { + if (ServerGameSticksPanel.Instance) + { + ServerGameSticksPanel.Instance.OnReceivedResult(msgObj.angle); + } + } } break; } diff --git a/Assets/Scripts/Server/ServerGameSticksPanel.cs b/Assets/Scripts/Server/ServerGameSticksPanel.cs index b228c01..8bad927 100644 --- a/Assets/Scripts/Server/ServerGameSticksPanel.cs +++ b/Assets/Scripts/Server/ServerGameSticksPanel.cs @@ -8,20 +8,32 @@ public class ServerGameSticksPanel : MonoBehaviour { public static ServerGameSticksPanel Instance; + private IncenseGameManager gameManager; private CustomerReportSystem customReportScript; private void Awake() { Instance = this; + gameManager = gameObject.GetComponentInChildren(includeInactive: true); customReportScript = gameObject.GetComponentInChildren(includeInactive: true); } // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { + gameManager.OnCountdownFinished = OnCountdownFinished; customReportScript.OnCustomerReportConfirmed = OnCustomerReportConfirmed; } - + + private void OnCountdownFinished() + { + //倒數時間到,直接跳轉頁面 + if (ServerWorkSceneController.Instance) + { + ServerWorkSceneController.Instance.processStep(17); + } + } + private void OnCustomerReportConfirmed(int[] values) { if (values.Length < 3) { return; } @@ -31,6 +43,18 @@ public class ServerGameSticksPanel : MonoBehaviour GlobalData.KARMA_SCORE = values[1]; GlobalData.SINCERITY_SCORE = values[2]; ServerWorkTopRightScore.Instance.UpdateScoreVals(); + + //跳轉頁面 + if (ServerWorkSceneController.Instance) + { + ServerWorkSceneController.Instance.processStep(17); + } + } + + public void OnReceivedResult(int angle) + { + //更新角度 + gameManager.SetReceivedAngle(angle); } // Update is called once per frame