Pause timescale when game is paused

This commit is contained in:
Michal Pikulski
2025-10-27 15:21:23 +01:00
parent 7005b70a0d
commit dad1f6498d
10 changed files with 57 additions and 1100 deletions

View File

@@ -62,19 +62,28 @@ public class SceneBrowserWindow : EditorWindow
if (GUILayout.Button("Refresh")) if (GUILayout.Button("Refresh"))
RefreshScenes(); RefreshScenes();
_scroll = EditorGUILayout.BeginScrollView(_scroll); _scroll = EditorGUILayout.BeginScrollView(_scroll);
// Create a safe copy to avoid collection modification during enumeration
var foldersCopy = _scenesByFolder.Keys.ToList();
// Top-level scenes // Top-level scenes
if (_scenesByFolder.ContainsKey("")) if (foldersCopy.Contains("") && _scenesByFolder.ContainsKey(""))
{ {
foreach (var scene in _scenesByFolder[""]) var topLevelScenes = _scenesByFolder[""].ToList();
foreach (var scene in topLevelScenes)
DrawSceneRow(scene); DrawSceneRow(scene);
EditorGUILayout.Space(); EditorGUILayout.Space();
} }
// Subfolders // Subfolders
foreach (var kvp in _scenesByFolder) foreach (var folderKey in foldersCopy)
{ {
if (string.IsNullOrEmpty(kvp.Key)) continue; if (string.IsNullOrEmpty(folderKey)) continue;
EditorGUILayout.LabelField(kvp.Key, EditorStyles.boldLabel); if (!_scenesByFolder.ContainsKey(folderKey)) continue;
foreach (var scene in kvp.Value)
EditorGUILayout.LabelField(folderKey, EditorStyles.boldLabel);
var scenesInFolder = _scenesByFolder[folderKey].ToList();
foreach (var scene in scenesInFolder)
DrawSceneRow(scene); DrawSceneRow(scene);
EditorGUILayout.Space(); EditorGUILayout.Space();
} }

File diff suppressed because one or more lines are too long

View File

@@ -123,8 +123,12 @@ namespace Core
/// <param name="shouldPause">True to pause; false to resume</param> /// <param name="shouldPause">True to pause; false to resume</param>
private void ApplyPause(bool shouldPause) private void ApplyPause(bool shouldPause)
{ {
// TODO: Do we want to stop time? // Only affect timescale if debug setting allows it
// Time.timeScale = shouldPause ? 0f : 1f; var debugSettings = GetDeveloperSettings<DebugSettings>();
if (debugSettings != null && debugSettings.PauseTimeOnPauseGame)
{
Time.timeScale = shouldPause ? 0f : 1f;
}
// Notify registered components // Notify registered components
foreach (var component in _pausableComponents) foreach (var component in _pausableComponents)
@@ -213,8 +217,9 @@ namespace Core
// Load developer settings // Load developer settings
var divingDevSettings = DeveloperSettingsProvider.Instance.GetSettings<DivingDeveloperSettings>(); var divingDevSettings = DeveloperSettingsProvider.Instance.GetSettings<DivingDeveloperSettings>();
var debugSettings = DeveloperSettingsProvider.Instance.GetSettings<DebugSettings>();
_developerSettingsLoaded = divingDevSettings != null; _developerSettingsLoaded = divingDevSettings != null && debugSettings != null;
if (_developerSettingsLoaded) if (_developerSettingsLoaded)
{ {

View File

@@ -25,8 +25,13 @@ namespace AppleHills.Core.Settings
[Tooltip("Should debug messages be show on screen in Editor")] [Tooltip("Should debug messages be show on screen in Editor")]
[SerializeField] private bool showDebugUiMessages = false; [SerializeField] private bool showDebugUiMessages = false;
[Header("Game Behavior Options")]
[Tooltip("Should Time.timeScale be set to 0 when the game is paused")]
[SerializeField] private bool pauseTimeOnPauseGame = true;
// Property getters // Property getters
public bool ShowDebugUiMessages => showDebugUiMessages; public bool ShowDebugUiMessages => showDebugUiMessages;
public bool PauseTimeOnPauseGame => pauseTimeOnPauseGame;
public override void OnValidate() public override void OnValidate()
{ {

View File

@@ -274,7 +274,7 @@ namespace UI.CardSystem
if (canvasGroup != null) if (canvasGroup != null)
{ {
canvasGroup.alpha = 0f; canvasGroup.alpha = 0f;
Tween.Value(0f, 1f, (value) => canvasGroup.alpha = value, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete); Tween.Value(0f, 1f, (value) => canvasGroup.alpha = value, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete, obeyTimescale: false);
} }
else else
{ {
@@ -288,7 +288,7 @@ namespace UI.CardSystem
// Simple fade out animation // Simple fade out animation
if (canvasGroup != null) if (canvasGroup != null)
{ {
Tween.Value(canvasGroup.alpha, 0f, (value) => canvasGroup.alpha = value, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete); Tween.Value(canvasGroup.alpha, 0f, (value) => canvasGroup.alpha = value, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete, obeyTimescale: false);
} }
else else
{ {

View File

@@ -177,7 +177,8 @@ namespace UI.CardSystem
pulseDuration/2, pulseDuration/2,
0, 0,
Tween.EaseIn); Tween.EaseIn);
}); },
obeyTimescale: false);
} }
} }
} }

View File

@@ -255,7 +255,7 @@ namespace UI.CardSystem
// Animate the booster pack opening // Animate the booster pack opening
Tween.LocalScale(boosterPackObject.transform, Vector3.zero, 0.3f, 0f, Tween.EaseInBack, Tween.LoopType.None, null, () => { Tween.LocalScale(boosterPackObject.transform, Vector3.zero, 0.3f, 0f, Tween.EaseInBack, Tween.LoopType.None, null, () => {
boosterPackObject.SetActive(false); boosterPackObject.SetActive(false);
}); }, obeyTimescale: false);
} }
if (openBoosterButton != null) if (openBoosterButton != null)
@@ -322,7 +322,7 @@ namespace UI.CardSystem
Debug.Log($"[BoosterOpeningPage] Card back {i} activated"); Debug.Log($"[BoosterOpeningPage] Card back {i} activated");
// Play reveal animation using Pixelplacement.Tween // Play reveal animation using Pixelplacement.Tween
Tween.LocalScale(cardBackObj.transform, Vector3.one, 0.5f, 0f, Tween.EaseOutBack); Tween.LocalScale(cardBackObj.transform, Vector3.one, 0.5f, 0f, Tween.EaseOutBack, obeyTimescale: false);
// Wait for animation delay // Wait for animation delay
yield return new WaitForSeconds(cardRevealDelay); yield return new WaitForSeconds(cardRevealDelay);
@@ -374,7 +374,7 @@ namespace UI.CardSystem
Transform cardBackTransform = cardBack.transform; Transform cardBackTransform = cardBack.transform;
// Step 1: Flip the card 90 degrees (showing the edge) // Step 1: Flip the card 90 degrees (showing the edge)
Tween.LocalRotation(cardBackTransform, new Vector3(0, 90, 0), flipAnimationDuration * 0.5f, 0); Tween.LocalRotation(cardBackTransform, new Vector3(0, 90, 0), flipAnimationDuration * 0.5f, 0, obeyTimescale: false);
// Wait for half the flip duration // Wait for half the flip duration
yield return new WaitForSeconds(flipAnimationDuration * 0.5f); yield return new WaitForSeconds(flipAnimationDuration * 0.5f);
@@ -405,7 +405,7 @@ namespace UI.CardSystem
} }
// Step 3: Finish the flip animation (from 90 degrees to 0) // Step 3: Finish the flip animation (from 90 degrees to 0)
Tween.LocalRotation(cardObj.transform, Vector3.zero, flipAnimationDuration * 0.5f, 0); Tween.LocalRotation(cardObj.transform, Vector3.zero, flipAnimationDuration * 0.5f, 0, obeyTimescale: false);
// Increment counter of revealed cards // Increment counter of revealed cards
_revealedCardCount++; _revealedCardCount++;
@@ -441,8 +441,8 @@ namespace UI.CardSystem
Vector3 originalScale = cardTransform.localScale; Vector3 originalScale = cardTransform.localScale;
// Sequence: Scale up slightly, then back to normal // Sequence: Scale up slightly, then back to normal
Tween.LocalScale(cardTransform, originalScale * 1.2f, 0.2f, 0.1f, Tween.EaseOutBack); Tween.LocalScale(cardTransform, originalScale * 1.2f, 0.2f, 0.1f, Tween.EaseOutBack, obeyTimescale: false);
Tween.LocalScale(cardTransform, originalScale, 0.15f, 0.3f, Tween.EaseIn); Tween.LocalScale(cardTransform, originalScale, 0.15f, 0.3f, Tween.EaseIn, obeyTimescale: false);
// Play sound effect based on rarity (if available) // Play sound effect based on rarity (if available)
// This would require audio source components to be set up // This would require audio source components to be set up
@@ -463,7 +463,7 @@ namespace UI.CardSystem
continueButton.gameObject.SetActive(true); continueButton.gameObject.SetActive(true);
continueButton.transform.localScale = Vector3.zero; continueButton.transform.localScale = Vector3.zero;
Tween.LocalScale(continueButton.transform, Vector3.one, 0.3f, 0f, Tween.EaseOutBack); Tween.LocalScale(continueButton.transform, Vector3.one, 0.3f, 0f, Tween.EaseOutBack, obeyTimescale: false);
} }
} }
@@ -542,8 +542,8 @@ namespace UI.CardSystem
Vector3 targetPos = card.transform.parent.InverseTransformPoint(backpackWorldPos); Vector3 targetPos = card.transform.parent.InverseTransformPoint(backpackWorldPos);
// Start the move animation - ensure no cancellation between animations // Start the move animation - ensure no cancellation between animations
Tween.LocalPosition(card.transform, targetPos, animationDuration, cardDelay * i, Tween.EaseInOut); Tween.LocalPosition(card.transform, targetPos, animationDuration, cardDelay * i, Tween.EaseInOut, obeyTimescale: false);
Tween.LocalScale(card.transform, Vector3.zero, animationDuration, cardDelay * i, Tween.EaseIn); Tween.LocalScale(card.transform, Vector3.zero, animationDuration, cardDelay * i, Tween.EaseIn, obeyTimescale: false);
Debug.Log($"[BoosterOpeningPage] Starting animation for card {i}"); Debug.Log($"[BoosterOpeningPage] Starting animation for card {i}");
} }
@@ -578,7 +578,7 @@ namespace UI.CardSystem
if (canvasGroup != null) if (canvasGroup != null)
{ {
canvasGroup.alpha = 0f; canvasGroup.alpha = 0f;
Tween.Value(0f, 1f, (value) => canvasGroup.alpha = value, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete); Tween.Value(0f, 1f, (value) => canvasGroup.alpha = value, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete, obeyTimescale: false);
} }
else else
{ {
@@ -595,7 +595,7 @@ namespace UI.CardSystem
// Simple fade out animation // Simple fade out animation
if (canvasGroup != null) if (canvasGroup != null)
{ {
Tween.Value(canvasGroup.alpha, 0f, (value) => canvasGroup.alpha = value, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete); Tween.Value(canvasGroup.alpha, 0f, (value) => canvasGroup.alpha = value, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete, obeyTimescale: false);
} }
else else
{ {

View File

@@ -268,7 +268,7 @@ namespace UI.CardSystem
// Animate the notification dot for feedback // Animate the notification dot for feedback
boosterNotificationDot.transform.localScale = Vector3.one * 1.2f; boosterNotificationDot.transform.localScale = Vector3.one * 1.2f;
Tween.LocalScale(boosterNotificationDot.transform, Vector3.one, 0.3f, 0f); Tween.LocalScale(boosterNotificationDot.transform, Vector3.one, 0.3f, 0f, obeyTimescale: false);
// Update visibility based on count // Update visibility based on count
UpdateBoosterVisibility(); UpdateBoosterVisibility();

View File

@@ -175,7 +175,7 @@ namespace UI.CardSystem
if (canvasGroup != null) if (canvasGroup != null)
{ {
canvasGroup.alpha = 0f; canvasGroup.alpha = 0f;
Tween.Value(0f, 1f, (value) => canvasGroup.alpha = value, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete); Tween.Value(0f, 1f, (value) => canvasGroup.alpha = value, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete, obeyTimescale: false);
} }
else else
{ {
@@ -192,7 +192,7 @@ namespace UI.CardSystem
// Simple fade out animation // Simple fade out animation
if (canvasGroup != null) if (canvasGroup != null)
{ {
Tween.Value(canvasGroup.alpha, 0f, (value) => canvasGroup.alpha = value, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete); Tween.Value(canvasGroup.alpha, 0f, (value) => canvasGroup.alpha = value, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete, obeyTimescale: false);
} }
else else
{ {

View File

@@ -13,3 +13,4 @@ MonoBehaviour:
m_Name: DebugSettings m_Name: DebugSettings
m_EditorClassIdentifier: AppleHillsScripts::AppleHills.Core.Settings.DebugSettings m_EditorClassIdentifier: AppleHillsScripts::AppleHills.Core.Settings.DebugSettings
showDebugUiMessages: 1 showDebugUiMessages: 1
pauseTimeOnPauseGame: 1