From 627ddacb10a8db87fb5d1760e693a2d7d0159b42 Mon Sep 17 00:00:00 2001 From: Ashby Issac Date: Mon, 23 Feb 2026 17:09:04 +0530 Subject: [PATCH] Fix: User dice timer system. Fix: User's dice roll attempt was not stopping while the game was paused. --- Assets/Scenes/Game.unity | 28 ++++++++-------- Assets/Scripts/Gameplay/GameplayManager.cs | 33 +++++++++++++++---- .../Scripts/UI/Pages/PopUp/PauseMenuPopup.cs | 2 +- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/Assets/Scenes/Game.unity b/Assets/Scenes/Game.unity index 9da61e5..7b40e18 100644 --- a/Assets/Scenes/Game.unity +++ b/Assets/Scenes/Game.unity @@ -15584,8 +15584,8 @@ RectTransform: m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 1 m_Children: [] - m_Father: {fileID: 5608193482405246780} - m_RootOrder: 3 + m_Father: {fileID: 5608193482973815123} + m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 1, y: 0} m_AnchorMax: {x: 1, y: 0} @@ -18146,7 +18146,7 @@ PrefabInstance: m_ObjectHideFlags: 0 serializedVersion: 2 m_Modification: - m_TransformParent: {fileID: 5608193482405246780} + m_TransformParent: {fileID: 5608193482973815123} m_Modifications: - target: {fileID: 1882416428171655664, guid: 94fc731c540da43c9ab09386da3501df, type: 3} propertyPath: m_Pivot.x @@ -18158,7 +18158,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1882416428171655664, guid: 94fc731c540da43c9ab09386da3501df, type: 3} propertyPath: m_RootOrder - value: 4 + value: 2 objectReference: {fileID: 0} - target: {fileID: 1882416428171655664, guid: 94fc731c540da43c9ab09386da3501df, type: 3} propertyPath: m_AnchorMax.x @@ -18202,15 +18202,15 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1882416428171655664, guid: 94fc731c540da43c9ab09386da3501df, type: 3} propertyPath: m_LocalRotation.x - value: 0 + value: -0 objectReference: {fileID: 0} - target: {fileID: 1882416428171655664, guid: 94fc731c540da43c9ab09386da3501df, type: 3} propertyPath: m_LocalRotation.y - value: 0 + value: -0 objectReference: {fileID: 0} - target: {fileID: 1882416428171655664, guid: 94fc731c540da43c9ab09386da3501df, type: 3} propertyPath: m_LocalRotation.z - value: 0 + value: -0 objectReference: {fileID: 0} - target: {fileID: 1882416428171655664, guid: 94fc731c540da43c9ab09386da3501df, type: 3} propertyPath: m_AnchoredPosition.x @@ -19183,7 +19183,7 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 5608193482973815123} - m_RootOrder: 2 + m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.00047905743, y: 0.019000001} m_AnchorMax: {x: 0.164, y: 0.13700001} @@ -24277,10 +24277,7 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: - {fileID: 5608193482794695410} - - {fileID: 5608193482610168847} - {fileID: 5608193483164820607} - - {fileID: 1489264326} - - {fileID: 1763545632} m_Father: {fileID: 5608193482973815123} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -24690,8 +24687,8 @@ RectTransform: m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] - m_Father: {fileID: 5608193482405246780} - m_RootOrder: 1 + m_Father: {fileID: 5608193482973815123} + m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} @@ -25398,6 +25395,9 @@ RectTransform: m_Children: - {fileID: 5608193482405246780} - {fileID: 5608193483424667982} + - {fileID: 1763545632} + - {fileID: 5608193482610168847} + - {fileID: 1489264326} - {fileID: 1854040023} m_Father: {fileID: 5608193482405325761} m_RootOrder: 1 @@ -25823,7 +25823,7 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 5608193482405246780} - m_RootOrder: 2 + m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} diff --git a/Assets/Scripts/Gameplay/GameplayManager.cs b/Assets/Scripts/Gameplay/GameplayManager.cs index 15424f3..389cc37 100644 --- a/Assets/Scripts/Gameplay/GameplayManager.cs +++ b/Assets/Scripts/Gameplay/GameplayManager.cs @@ -50,6 +50,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader private PlayerType currentPlayerTypeTurn; private TimerSystem currentPlayerTurnTimer; + private TimerSystem savedCurrentPlayerTurnTimerInst; private int currentPlayerTurnIndex = 0; private List allPlayerTypes = new List(); @@ -95,7 +96,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader public List PlayerDatas => playerDatas; public List PlayerTypesCollection => allPlayerTypes; - public Action OnGameResumed = null; + public Action onGameResumed = null; public void Initialize() { @@ -285,6 +286,13 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader onComplete?.Invoke(); }, inProgress: (remTime) => { + if (HasGamePausedForUser()) + { + savedCurrentPlayerTurnTimerInst = currentPlayerTurnTimer; + currentPlayerTurnTimer = null; + + return; + } uIManager.UpdatePlayerTurnText(currentPlayerTypeTurn, currentPlayerMaxTime - (int)remTime); }); } @@ -1195,13 +1203,18 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader index); } + private bool HasGamePausedForUser() + { + return (botTypesInGame == null || !botTypesInGame.Contains(currentPlayerTypeTurn)) && + GameManager.CurrentGameState == GameState.IsPaused; + } + public void CheckForGamePause(Action onComplete) { Debug.Log($"CheckForGamePause: {GameManager.CurrentGameState == GameState.IsPaused}"); - if ((botTypesInGame == null || !botTypesInGame.Contains(currentPlayerTypeTurn)) && - GameManager.CurrentGameState == GameState.IsPaused) + if (HasGamePausedForUser()) { - OnGameResumed = onComplete; + onGameResumed = onComplete; } else { @@ -1209,6 +1222,13 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader } } + public void OnGameResumed() + { + onGameResumed?.Invoke(); + currentPlayerTurnTimer = savedCurrentPlayerTurnTimerInst; + savedCurrentPlayerTurnTimerInst = null; + } + private void MoveThroughFinishingPath(PlayerPawn playerPawn, int index, int targetIndex) { UpdatePlayerState(playerPawn, PlayerState.InFinishingPath); @@ -1233,7 +1253,7 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader { if (playerPawn.CurrentTileIndex == TilesManager.GetFinishingTileDataLength(currentPlayerTypeTurn) - 1) { - OnGameResumed = null; + onGameResumed = null; Tile tile = TilesManager.RetrieveFinishingTileBasedOnIndex(playerPawn.PlayerType, playerPawn.CurrentTileIndex); tile.InitPlayerPawn(playerPawn, playerPawn.PlayerType); // ShowUpdatedPlayerCountOnTile(playerPawn); @@ -1389,8 +1409,9 @@ public class GameplayManager : MonoBehaviour, IBase, IBootLoader, IDataLoader ResetGameRestartData(); currentPlayerTurnTimer?.KillTimer(); + savedCurrentPlayerTurnTimerInst = null; currentPlayerTurnTimer = null; - OnGameResumed = null; + onGameResumed = null; playerDatas = null; allPlayerTypes = null; diff --git a/Assets/Scripts/UI/Pages/PopUp/PauseMenuPopup.cs b/Assets/Scripts/UI/Pages/PopUp/PauseMenuPopup.cs index a8901dd..e3ac095 100644 --- a/Assets/Scripts/UI/Pages/PopUp/PauseMenuPopup.cs +++ b/Assets/Scripts/UI/Pages/PopUp/PauseMenuPopup.cs @@ -40,7 +40,7 @@ public class PauseMenuPopup : PopupBase screenManager.ShowScreen(ScreenType.InGameHUDScreen); SetGameModeHandler(); - gameModeHandler.GameplayManager.OnGameResumed?.Invoke(); + gameModeHandler.GameplayManager.OnGameResumed(); } private void OnClick_HomeButton()